154 lines
4.6 KiB
C#
154 lines
4.6 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using System.Runtime.Serialization;
|
|
using Umbraco.Core.Models.EntityBase;
|
|
|
|
namespace Umbraco.Core.Models
|
|
{
|
|
/// <summary>
|
|
/// Represents a Macro Property
|
|
/// </summary>
|
|
[Serializable]
|
|
[DataContract(IsReference = true)]
|
|
internal class MacroProperty : TracksChangesEntityBase, IMacroProperty, IRememberBeingDirty
|
|
{
|
|
public MacroProperty()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ctor for creating a new property
|
|
/// </summary>
|
|
/// <param name="alias"></param>
|
|
/// <param name="name"></param>
|
|
/// <param name="sortOrder"></param>
|
|
/// <param name="editorAlias"></param>
|
|
public MacroProperty(string @alias, string name, int sortOrder, string editorAlias)
|
|
{
|
|
_alias = alias;
|
|
_name = name;
|
|
_sortOrder = sortOrder;
|
|
_editorAlias = editorAlias;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ctor for creating an existing property
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="alias"></param>
|
|
/// <param name="name"></param>
|
|
/// <param name="sortOrder"></param>
|
|
/// <param name="editorAlias"></param>
|
|
internal MacroProperty(int id, string @alias, string name, int sortOrder, string editorAlias)
|
|
{
|
|
_id = id;
|
|
_alias = alias;
|
|
_name = name;
|
|
_sortOrder = sortOrder;
|
|
_editorAlias = editorAlias;
|
|
}
|
|
|
|
private string _alias;
|
|
private string _name;
|
|
private int _sortOrder;
|
|
private int _id;
|
|
private string _editorAlias;
|
|
|
|
private static readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo<MacroProperty, string>(x => x.Alias);
|
|
private static readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<MacroProperty, string>(x => x.Name);
|
|
private static readonly PropertyInfo SortOrderSelector = ExpressionHelper.GetPropertyInfo<MacroProperty, int>(x => x.SortOrder);
|
|
private static readonly PropertyInfo IdSelector = ExpressionHelper.GetPropertyInfo<Entity, int>(x => x.Id);
|
|
private static readonly PropertyInfo PropertyTypeSelector = ExpressionHelper.GetPropertyInfo<MacroProperty, string>(x => x.EditorAlias);
|
|
|
|
/// <summary>
|
|
/// Gets or sets the Alias of the Property
|
|
/// </summary>
|
|
[DataMember]
|
|
public int Id
|
|
{
|
|
get { return _id; }
|
|
set
|
|
{
|
|
SetPropertyValueAndDetectChanges(o =>
|
|
{
|
|
_id = value;
|
|
return _alias;
|
|
}, _alias, IdSelector);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the Alias of the Property
|
|
/// </summary>
|
|
[DataMember]
|
|
public string Alias
|
|
{
|
|
get { return _alias; }
|
|
set
|
|
{
|
|
SetPropertyValueAndDetectChanges(o =>
|
|
{
|
|
_alias = value;
|
|
return _alias;
|
|
}, _alias, AliasSelector);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the Name of the Property
|
|
/// </summary>
|
|
[DataMember]
|
|
public string Name
|
|
{
|
|
get { return _name; }
|
|
set
|
|
{
|
|
SetPropertyValueAndDetectChanges(o =>
|
|
{
|
|
_name = value;
|
|
return _name;
|
|
}, _name, NameSelector);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the Sort Order of the Property
|
|
/// </summary>
|
|
[DataMember]
|
|
public int SortOrder
|
|
{
|
|
get { return _sortOrder; }
|
|
set
|
|
{
|
|
SetPropertyValueAndDetectChanges(o =>
|
|
{
|
|
_sortOrder = value;
|
|
return _sortOrder;
|
|
}, _sortOrder, SortOrderSelector);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the Type for this Property
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The MacroPropertyTypes acts as a plugin for Macros.
|
|
/// All types was previously contained in the database, but has been ported to code.
|
|
/// </remarks>
|
|
[DataMember]
|
|
public string EditorAlias
|
|
|
|
{
|
|
get { return _editorAlias; }
|
|
set
|
|
{
|
|
SetPropertyValueAndDetectChanges(o =>
|
|
{
|
|
_editorAlias = value;
|
|
return _editorAlias;
|
|
}, _editorAlias, PropertyTypeSelector);
|
|
}
|
|
}
|
|
}
|
|
} |