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