diff --git a/src/Umbraco.Core/Models/AuditEntry.cs b/src/Umbraco.Core/Models/AuditEntry.cs index 2076e5328c..d12163f394 100644 --- a/src/Umbraco.Core/Models/AuditEntry.cs +++ b/src/Umbraco.Core/Models/AuditEntry.cs @@ -1,5 +1,4 @@ using System; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Models.Entities; @@ -12,8 +11,6 @@ namespace Umbraco.Core.Models [DataContract(IsReference = true)] internal class AuditEntry : EntityBase, IAuditEntry { - private static PropertySelectors _selectors; - private int _performingUserId; private string _performingDetails; private string _performingIp; @@ -22,38 +19,25 @@ namespace Umbraco.Core.Models private string _eventType; private string _eventDetails; - private static PropertySelectors Selectors => _selectors ?? (_selectors = new PropertySelectors()); - - private class PropertySelectors - { - public readonly PropertyInfo PerformingUserId = ExpressionHelper.GetPropertyInfo(x => x.PerformingUserId); - public readonly PropertyInfo PerformingDetails = ExpressionHelper.GetPropertyInfo(x => x.PerformingDetails); - public readonly PropertyInfo PerformingIp = ExpressionHelper.GetPropertyInfo(x => x.PerformingIp); - public readonly PropertyInfo AffectedUserId = ExpressionHelper.GetPropertyInfo(x => x.AffectedUserId); - public readonly PropertyInfo AffectedDetails = ExpressionHelper.GetPropertyInfo(x => x.AffectedDetails); - public readonly PropertyInfo EventType = ExpressionHelper.GetPropertyInfo(x => x.EventType); - public readonly PropertyInfo EventDetails = ExpressionHelper.GetPropertyInfo(x => x.EventDetails); - } - /// public int PerformingUserId { get => _performingUserId; - set => SetPropertyValueAndDetectChanges(value, ref _performingUserId, Selectors.PerformingUserId); + set => SetPropertyValueAndDetectChanges(value, ref _performingUserId, nameof(PerformingUserId)); } /// public string PerformingDetails { get => _performingDetails; - set => SetPropertyValueAndDetectChanges(value, ref _performingDetails, Selectors.PerformingDetails); + set => SetPropertyValueAndDetectChanges(value, ref _performingDetails, nameof(PerformingDetails)); } /// public string PerformingIp { get => _performingIp; - set => SetPropertyValueAndDetectChanges(value, ref _performingIp, Selectors.PerformingIp); + set => SetPropertyValueAndDetectChanges(value, ref _performingIp, nameof(PerformingIp)); } /// @@ -64,31 +48,31 @@ namespace Umbraco.Core.Models } /// - public int AffectedUserId + public int AffectedUserId { get => _affectedUserId; - set => SetPropertyValueAndDetectChanges(value, ref _affectedUserId, Selectors.AffectedUserId); + set => SetPropertyValueAndDetectChanges(value, ref _affectedUserId, nameof(AffectedUserId)); } /// - public string AffectedDetails + public string AffectedDetails { get => _affectedDetails; - set => SetPropertyValueAndDetectChanges(value, ref _affectedDetails, Selectors.AffectedDetails); + set => SetPropertyValueAndDetectChanges(value, ref _affectedDetails, nameof(AffectedDetails)); } /// - public string EventType + public string EventType { get => _eventType; - set => SetPropertyValueAndDetectChanges(value, ref _eventType, Selectors.EventType); + set => SetPropertyValueAndDetectChanges(value, ref _eventType, nameof(EventType)); } /// - public string EventDetails + public string EventDetails { get => _eventDetails; - set => SetPropertyValueAndDetectChanges(value, ref _eventDetails, Selectors.EventDetails); + set => SetPropertyValueAndDetectChanges(value, ref _eventDetails, nameof(EventDetails)); } } } diff --git a/src/Umbraco.Core/Models/Consent.cs b/src/Umbraco.Core/Models/Consent.cs index 87dd9767a0..4f7543fd59 100644 --- a/src/Umbraco.Core/Models/Consent.cs +++ b/src/Umbraco.Core/Models/Consent.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Models.Entities; @@ -13,8 +12,6 @@ namespace Umbraco.Core.Models [DataContract(IsReference = true)] internal class Consent : EntityBase, IConsent { - private static PropertySelectors _selector; - private bool _current; private string _source; private string _context; @@ -22,24 +19,11 @@ namespace Umbraco.Core.Models private ConsentState _state; private string _comment; - // ReSharper disable once ClassNeverInstantiated.Local - private class PropertySelectors - { - public readonly PropertyInfo Current = ExpressionHelper.GetPropertyInfo(x => x.Current); - public readonly PropertyInfo Source = ExpressionHelper.GetPropertyInfo(x => x.Source); - public readonly PropertyInfo Context = ExpressionHelper.GetPropertyInfo(x => x.Context); - public readonly PropertyInfo Action = ExpressionHelper.GetPropertyInfo(x => x.Action); - public readonly PropertyInfo State = ExpressionHelper.GetPropertyInfo(x => x.State); - public readonly PropertyInfo Comment = ExpressionHelper.GetPropertyInfo(x => x.Comment); - } - - private static PropertySelectors Selectors => _selector ?? (_selector = new PropertySelectors()); - /// public bool Current { get => _current; - set => SetPropertyValueAndDetectChanges(value, ref _current, Selectors.Current); + set => SetPropertyValueAndDetectChanges(value, ref _current, nameof(Current)); } /// @@ -49,7 +33,7 @@ namespace Umbraco.Core.Models set { if (string.IsNullOrWhiteSpace(value)) throw new ArgumentException(nameof(value)); - SetPropertyValueAndDetectChanges(value, ref _source, Selectors.Source); + SetPropertyValueAndDetectChanges(value, ref _source, nameof(Source)); } } @@ -60,7 +44,7 @@ namespace Umbraco.Core.Models set { if (string.IsNullOrWhiteSpace(value)) throw new ArgumentException(nameof(value)); - SetPropertyValueAndDetectChanges(value, ref _context, Selectors.Context); + SetPropertyValueAndDetectChanges(value, ref _context, nameof(Context)); } } @@ -71,7 +55,7 @@ namespace Umbraco.Core.Models set { if (string.IsNullOrWhiteSpace(value)) throw new ArgumentException(nameof(value)); - SetPropertyValueAndDetectChanges(value, ref _action, Selectors.Action); + SetPropertyValueAndDetectChanges(value, ref _action, nameof(Action)); } } @@ -81,14 +65,14 @@ namespace Umbraco.Core.Models get => _state; // note: we probably should validate the state here, but since the // enum is [Flags] with many combinations, this could be expensive - set => SetPropertyValueAndDetectChanges(value, ref _state, Selectors.State); + set => SetPropertyValueAndDetectChanges(value, ref _state, nameof(State)); } /// public string Comment { get => _comment; - set => SetPropertyValueAndDetectChanges(value, ref _comment, Selectors.Comment); + set => SetPropertyValueAndDetectChanges(value, ref _comment, nameof(Comment)); } /// diff --git a/src/Umbraco.Core/Models/Content.cs b/src/Umbraco.Core/Models/Content.cs index 16b28e088a..dd4ba13c33 100644 --- a/src/Umbraco.Core/Models/Content.cs +++ b/src/Umbraco.Core/Models/Content.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Exceptions; @@ -23,8 +22,6 @@ namespace Umbraco.Core.Models private ContentCultureInfosCollection _publishInfosOrig; private HashSet _editedCultures; - private static readonly Lazy Ps = new Lazy(); - /// /// Constructor for creating a Content object /// @@ -81,15 +78,6 @@ namespace Umbraco.Core.Models PublishedVersionId = 0; } - // ReSharper disable once ClassNeverInstantiated.Local - private class PropertySelectors - { - public readonly PropertyInfo TemplateSelector = ExpressionHelper.GetPropertyInfo(x => x.TemplateId); - public readonly PropertyInfo PublishedSelector = ExpressionHelper.GetPropertyInfo(x => x.Published); - public readonly PropertyInfo ContentScheduleSelector = ExpressionHelper.GetPropertyInfo(x => x.ContentSchedule); - public readonly PropertyInfo PublishCultureInfosSelector = ExpressionHelper.GetPropertyInfo>(x => x.PublishCultureInfos); - } - /// [DoNotClone] public ContentScheduleCollection ContentSchedule @@ -107,7 +95,7 @@ namespace Umbraco.Core.Models { if(_schedule != null) _schedule.CollectionChanged -= ScheduleCollectionChanged; - SetPropertyValueAndDetectChanges(value, ref _schedule, Ps.Value.ContentScheduleSelector); + SetPropertyValueAndDetectChanges(value, ref _schedule, nameof(ContentSchedule)); if (_schedule != null) _schedule.CollectionChanged += ScheduleCollectionChanged; } @@ -120,7 +108,7 @@ namespace Umbraco.Core.Models /// private void ScheduleCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { - OnPropertyChanged(Ps.Value.ContentScheduleSelector); + OnPropertyChanged(nameof(ContentSchedule)); } /// @@ -135,7 +123,7 @@ namespace Umbraco.Core.Models public int? TemplateId { get => _templateId; - set => SetPropertyValueAndDetectChanges(value, ref _templateId, Ps.Value.TemplateSelector); + set => SetPropertyValueAndDetectChanges(value, ref _templateId, nameof(TemplateId)); } /// @@ -151,7 +139,7 @@ namespace Umbraco.Core.Models // - the ContentRepository when updating a content entity internal set { - SetPropertyValueAndDetectChanges(value, ref _published, Ps.Value.PublishedSelector); + SetPropertyValueAndDetectChanges(value, ref _published, nameof(Published)); _publishedState = _published ? PublishedState.Published : PublishedState.Unpublished; } } @@ -332,7 +320,7 @@ namespace Umbraco.Core.Models /// private void PublishNamesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { - OnPropertyChanged(Ps.Value.PublishCultureInfosSelector); + OnPropertyChanged(nameof(PublishCultureInfos)); } [IgnoreDataMember] diff --git a/src/Umbraco.Core/Models/ContentBase.cs b/src/Umbraco.Core/Models/ContentBase.cs index ca1152a9a4..a1fb5da308 100644 --- a/src/Umbraco.Core/Models/ContentBase.cs +++ b/src/Umbraco.Core/Models/ContentBase.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.Linq; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Exceptions; using Umbraco.Core.Models.Entities; @@ -19,7 +18,6 @@ namespace Umbraco.Core.Models public abstract class ContentBase : TreeEntityBase, IContentBase { protected static readonly ContentCultureInfosCollection NoInfos = new ContentCultureInfosCollection(); - private static readonly Lazy Ps = new Lazy(); private int _contentTypeId; protected IContentTypeComposition ContentTypeBase; @@ -62,18 +60,9 @@ namespace Umbraco.Core.Models _properties.EnsurePropertyTypes(PropertyTypes); } - // ReSharper disable once ClassNeverInstantiated.Local - private class PropertySelectors - { - public readonly PropertyInfo DefaultContentTypeIdSelector = ExpressionHelper.GetPropertyInfo(x => x.ContentTypeId); - public readonly PropertyInfo PropertyCollectionSelector = ExpressionHelper.GetPropertyInfo(x => x.Properties); - public readonly PropertyInfo WriterSelector = ExpressionHelper.GetPropertyInfo(x => x.WriterId); - public readonly PropertyInfo CultureInfosSelector = ExpressionHelper.GetPropertyInfo>(x => x.CultureInfos); - } - protected void PropertiesChanged(object sender, NotifyCollectionChangedEventArgs e) { - OnPropertyChanged(Ps.Value.PropertyCollectionSelector); + OnPropertyChanged(nameof(Properties)); } /// @@ -83,7 +72,7 @@ namespace Umbraco.Core.Models public virtual int WriterId { get => _writerId; - set => SetPropertyValueAndDetectChanges(value, ref _writerId, Ps.Value.WriterSelector); + set => SetPropertyValueAndDetectChanges(value, ref _writerId, nameof(WriterId)); } [IgnoreDataMember] @@ -105,7 +94,7 @@ namespace Umbraco.Core.Models } return _contentTypeId; } - protected set => SetPropertyValueAndDetectChanges(value, ref _contentTypeId, Ps.Value.DefaultContentTypeIdSelector); + protected set => SetPropertyValueAndDetectChanges(value, ref _contentTypeId, nameof(ContentTypeId)); } /// @@ -251,7 +240,7 @@ namespace Umbraco.Core.Models /// private void CultureInfosCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { - OnPropertyChanged(Ps.Value.CultureInfosSelector); + OnPropertyChanged(nameof(CultureInfos)); } #endregion diff --git a/src/Umbraco.Core/Models/ContentCultureInfos.cs b/src/Umbraco.Core/Models/ContentCultureInfos.cs index f51e3a275a..c8c4bea56a 100644 --- a/src/Umbraco.Core/Models/ContentCultureInfos.cs +++ b/src/Umbraco.Core/Models/ContentCultureInfos.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Reflection; using Umbraco.Core.Exceptions; using Umbraco.Core.Models.Entities; @@ -13,7 +12,6 @@ namespace Umbraco.Core.Models { private DateTime _date; private string _name; - private static readonly Lazy Ps = new Lazy(); /// /// Initializes a new instance of the class. @@ -46,7 +44,7 @@ namespace Umbraco.Core.Models public string Name { get => _name; - set => SetPropertyValueAndDetectChanges(value, ref _name, Ps.Value.NameSelector); + set => SetPropertyValueAndDetectChanges(value, ref _name, nameof(Name)); } /// @@ -55,7 +53,7 @@ namespace Umbraco.Core.Models public DateTime Date { get => _date; - set => SetPropertyValueAndDetectChanges(value, ref _date, Ps.Value.DateSelector); + set => SetPropertyValueAndDetectChanges(value, ref _date, nameof(Date)); } /// @@ -102,12 +100,5 @@ namespace Umbraco.Core.Models Deconstruct(out culture, out name); date = Date; } - - // ReSharper disable once ClassNeverInstantiated.Local - private class PropertySelectors - { - public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo(x => x.Name); - public readonly PropertyInfo DateSelector = ExpressionHelper.GetPropertyInfo(x => x.Date); - } } } diff --git a/src/Umbraco.Core/Models/ContentType.cs b/src/Umbraco.Core/Models/ContentType.cs index 4b9831682c..61fabe6fb0 100644 --- a/src/Umbraco.Core/Models/ContentType.cs +++ b/src/Umbraco.Core/Models/ContentType.cs @@ -13,7 +13,6 @@ namespace Umbraco.Core.Models [DataContract(IsReference = true)] public class ContentType : ContentTypeCompositionBase, IContentType { - private static readonly Lazy Ps = new Lazy(); public const bool IsPublishingConst = true; private int _defaultTemplate; @@ -45,17 +44,10 @@ namespace Umbraco.Core.Models /// public override bool IsPublishing => IsPublishingConst; - // ReSharper disable once ClassNeverInstantiated.Local - private class PropertySelectors - { - public readonly PropertyInfo DefaultTemplateSelector = ExpressionHelper.GetPropertyInfo(x => x.DefaultTemplateId); - public readonly PropertyInfo AllowedTemplatesSelector = ExpressionHelper.GetPropertyInfo>(x => x.AllowedTemplates); - - //Custom comparer for enumerable - public readonly DelegateEqualityComparer> TemplateComparer = new DelegateEqualityComparer>( - (templates, enumerable) => templates.UnsortedSequenceEqual(enumerable), - templates => templates.GetHashCode()); - } + //Custom comparer for enumerable + private static readonly DelegateEqualityComparer> TemplateComparer = new DelegateEqualityComparer>( + (templates, enumerable) => templates.UnsortedSequenceEqual(enumerable), + templates => templates.GetHashCode()); /// /// Gets or sets the alias of the default Template. @@ -75,8 +67,8 @@ namespace Umbraco.Core.Models [DataMember] internal int DefaultTemplateId { - get { return _defaultTemplate; } - set { SetPropertyValueAndDetectChanges(value, ref _defaultTemplate, Ps.Value.DefaultTemplateSelector); } + get => _defaultTemplate; + set => SetPropertyValueAndDetectChanges(value, ref _defaultTemplate, nameof(DefaultTemplateId)); } /// @@ -91,7 +83,7 @@ namespace Umbraco.Core.Models get => _allowedTemplates; set { - SetPropertyValueAndDetectChanges(value, ref _allowedTemplates, Ps.Value.AllowedTemplatesSelector, Ps.Value.TemplateComparer); + SetPropertyValueAndDetectChanges(value, ref _allowedTemplates, nameof(AllowedTemplates), TemplateComparer); if (_allowedTemplates.Any(x => x.Id == _defaultTemplate) == false) DefaultTemplateId = 0; diff --git a/src/Umbraco.Core/Models/ContentTypeBase.cs b/src/Umbraco.Core/Models/ContentTypeBase.cs index 3da2838d0e..2aa114a88f 100644 --- a/src/Umbraco.Core/Models/ContentTypeBase.cs +++ b/src/Umbraco.Core/Models/ContentTypeBase.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.Linq; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Models.Entities; using Umbraco.Core.Strings; @@ -18,8 +17,6 @@ namespace Umbraco.Core.Models [DebuggerDisplay("Id: {Id}, Name: {Name}, Alias: {Alias}")] public abstract class ContentTypeBase : TreeEntityBase, IContentTypeBase { - private static readonly Lazy Ps = new Lazy(); - private string _alias; private string _description; private string _icon = "icon-folder"; @@ -83,37 +80,20 @@ namespace Umbraco.Core.Models /// public abstract bool IsPublishing { get; } - // ReSharper disable once ClassNeverInstantiated.Local - private class PropertySelectors - { - public readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo(x => x.Alias); - public readonly PropertyInfo DescriptionSelector = ExpressionHelper.GetPropertyInfo(x => x.Description); - public readonly PropertyInfo IconSelector = ExpressionHelper.GetPropertyInfo(x => x.Icon); - public readonly PropertyInfo ThumbnailSelector = ExpressionHelper.GetPropertyInfo(x => x.Thumbnail); - public readonly PropertyInfo AllowedAsRootSelector = ExpressionHelper.GetPropertyInfo(x => x.AllowedAsRoot); - public readonly PropertyInfo IsElementSelector = ExpressionHelper.GetPropertyInfo(x => x.IsElement); - public readonly PropertyInfo IsContainerSelector = ExpressionHelper.GetPropertyInfo(x => x.IsContainer); - public readonly PropertyInfo AllowedContentTypesSelector = ExpressionHelper.GetPropertyInfo>(x => x.AllowedContentTypes); - public readonly PropertyInfo PropertyGroupsSelector = ExpressionHelper.GetPropertyInfo(x => x.PropertyGroups); - public readonly PropertyInfo PropertyTypesSelector = ExpressionHelper.GetPropertyInfo>(x => x.PropertyTypes); - public readonly PropertyInfo HasPropertyTypeBeenRemovedSelector = ExpressionHelper.GetPropertyInfo(x => x.HasPropertyTypeBeenRemoved); - public readonly PropertyInfo VaryBy = ExpressionHelper.GetPropertyInfo(x => x.Variations); - - //Custom comparer for enumerable - public readonly DelegateEqualityComparer> ContentTypeSortComparer = - new DelegateEqualityComparer>( - (sorts, enumerable) => sorts.UnsortedSequenceEqual(enumerable), - sorts => sorts.GetHashCode()); - } + //Custom comparer for enumerable + private static readonly DelegateEqualityComparer> ContentTypeSortComparer = + new DelegateEqualityComparer>( + (sorts, enumerable) => sorts.UnsortedSequenceEqual(enumerable), + sorts => sorts.GetHashCode()); protected void PropertyGroupsChanged(object sender, NotifyCollectionChangedEventArgs e) { - OnPropertyChanged(Ps.Value.PropertyGroupsSelector); + OnPropertyChanged(nameof(PropertyGroups)); } protected void PropertyTypesChanged(object sender, NotifyCollectionChangedEventArgs e) { - OnPropertyChanged(Ps.Value.PropertyTypesSelector); + OnPropertyChanged(nameof(PropertyTypes)); } /// @@ -126,7 +106,7 @@ namespace Umbraco.Core.Models set => SetPropertyValueAndDetectChanges( value.ToCleanString(CleanStringType.Alias | CleanStringType.UmbracoCase), ref _alias, - Ps.Value.AliasSelector); + nameof(Alias)); } /// @@ -136,7 +116,7 @@ namespace Umbraco.Core.Models public string Description { get => _description; - set => SetPropertyValueAndDetectChanges(value, ref _description, Ps.Value.DescriptionSelector); + set => SetPropertyValueAndDetectChanges(value, ref _description, nameof(Description)); } /// @@ -146,7 +126,7 @@ namespace Umbraco.Core.Models public string Icon { get => _icon; - set => SetPropertyValueAndDetectChanges(value, ref _icon, Ps.Value.IconSelector); + set => SetPropertyValueAndDetectChanges(value, ref _icon, nameof(Icon)); } /// @@ -156,7 +136,7 @@ namespace Umbraco.Core.Models public string Thumbnail { get => _thumbnail; - set => SetPropertyValueAndDetectChanges(value, ref _thumbnail, Ps.Value.ThumbnailSelector); + set => SetPropertyValueAndDetectChanges(value, ref _thumbnail, nameof(Thumbnail)); } /// @@ -166,7 +146,7 @@ namespace Umbraco.Core.Models public bool AllowedAsRoot { get => _allowedAsRoot; - set => SetPropertyValueAndDetectChanges(value, ref _allowedAsRoot, Ps.Value.AllowedAsRootSelector); + set => SetPropertyValueAndDetectChanges(value, ref _allowedAsRoot, nameof(AllowedAsRoot)); } /// @@ -179,7 +159,7 @@ namespace Umbraco.Core.Models public bool IsContainer { get => _isContainer; - set => SetPropertyValueAndDetectChanges(value, ref _isContainer, Ps.Value.IsContainerSelector); + set => SetPropertyValueAndDetectChanges(value, ref _isContainer, nameof(IsContainer)); } /// @@ -187,7 +167,7 @@ namespace Umbraco.Core.Models public bool IsElement { get => _isElement; - set => SetPropertyValueAndDetectChanges(value, ref _isElement, Ps.Value.IsElementSelector); + set => SetPropertyValueAndDetectChanges(value, ref _isElement, nameof(IsElement)); } /// @@ -197,8 +177,8 @@ namespace Umbraco.Core.Models public IEnumerable AllowedContentTypes { get => _allowedContentTypes; - set => SetPropertyValueAndDetectChanges(value, ref _allowedContentTypes, Ps.Value.AllowedContentTypesSelector, - Ps.Value.ContentTypeSortComparer); + set => SetPropertyValueAndDetectChanges(value, ref _allowedContentTypes, nameof(AllowedContentTypes), + ContentTypeSortComparer); } /// @@ -207,7 +187,7 @@ namespace Umbraco.Core.Models public virtual ContentVariation Variations { get => _variations; - set => SetPropertyValueAndDetectChanges(value, ref _variations, Ps.Value.VaryBy); + set => SetPropertyValueAndDetectChanges(value, ref _variations, nameof(Variations)); } /// @@ -295,7 +275,7 @@ namespace Umbraco.Core.Models private set { _hasPropertyTypeBeenRemoved = value; - OnPropertyChanged(Ps.Value.HasPropertyTypeBeenRemovedSelector); + OnPropertyChanged(nameof(HasPropertyTypeBeenRemoved)); } } @@ -388,7 +368,7 @@ namespace Umbraco.Core.Models if (!HasPropertyTypeBeenRemoved) { HasPropertyTypeBeenRemoved = true; - OnPropertyChanged(Ps.Value.PropertyTypesSelector); + OnPropertyChanged(nameof(PropertyTypes)); } break; } @@ -400,7 +380,7 @@ namespace Umbraco.Core.Models if (!HasPropertyTypeBeenRemoved) { HasPropertyTypeBeenRemoved = true; - OnPropertyChanged(Ps.Value.PropertyTypesSelector); + OnPropertyChanged(nameof(PropertyTypes)); } } } @@ -424,7 +404,7 @@ namespace Umbraco.Core.Models // actually remove the group PropertyGroups.RemoveItem(propertyGroupName); - OnPropertyChanged(Ps.Value.PropertyGroupsSelector); + OnPropertyChanged(nameof(PropertyGroups)); } /// diff --git a/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs b/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs index 08b9f74802..ec6f803107 100644 --- a/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs +++ b/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Exceptions; @@ -14,8 +13,6 @@ namespace Umbraco.Core.Models [DataContract(IsReference = true)] public abstract class ContentTypeCompositionBase : ContentTypeBase, IContentTypeComposition { - private static readonly Lazy Ps = new Lazy(); - private List _contentTypeComposition = new List(); internal List RemovedContentTypeKeyTracker = new List(); @@ -32,13 +29,6 @@ namespace Umbraco.Core.Models AddContentType(parent); } - // ReSharper disable once ClassNeverInstantiated.Local - private class PropertySelectors - { - public readonly PropertyInfo ContentTypeCompositionSelector = - ExpressionHelper.GetPropertyInfo>(x => x.ContentTypeComposition); - } - /// /// Gets or sets the content types that compose this content type. /// @@ -49,7 +39,7 @@ namespace Umbraco.Core.Models set { _contentTypeComposition = value.ToList(); - OnPropertyChanged(Ps.Value.ContentTypeCompositionSelector); + OnPropertyChanged(nameof(ContentTypeComposition)); } } @@ -161,7 +151,7 @@ namespace Umbraco.Core.Models throw new InvalidCompositionException(Alias, contentType.Alias, conflictingPropertyTypeAliases.ToArray()); _contentTypeComposition.Add(contentType); - OnPropertyChanged(Ps.Value.ContentTypeCompositionSelector); + OnPropertyChanged(nameof(ContentTypeComposition)); return true; } return false; @@ -187,7 +177,7 @@ namespace Umbraco.Core.Models if (compositionIdsToRemove.Any()) RemovedContentTypeKeyTracker.AddRange(compositionIdsToRemove); - OnPropertyChanged(Ps.Value.ContentTypeCompositionSelector); + OnPropertyChanged(nameof(ContentTypeComposition)); return _contentTypeComposition.Remove(contentTypeComposition); } return false; diff --git a/src/Umbraco.Core/Models/DataType.cs b/src/Umbraco.Core/Models/DataType.cs index 4f0d0d6c31..8745e6dbec 100644 --- a/src/Umbraco.Core/Models/DataType.cs +++ b/src/Umbraco.Core/Models/DataType.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Reflection; using System.Runtime.Serialization; using Newtonsoft.Json; using Umbraco.Core.Models.Entities; @@ -15,8 +14,6 @@ namespace Umbraco.Core.Models [DataContract(IsReference = true)] public class DataType : TreeEntityBase, IDataType { - private static PropertySelectors _selectors; - private IDataEditor _editor; private ValueStorageType _databaseType; private object _configuration; @@ -35,15 +32,6 @@ namespace Umbraco.Core.Models Configuration = _editor.GetConfigurationEditor().DefaultConfigurationObject; } - private static PropertySelectors Selectors => _selectors ?? (_selectors = new PropertySelectors()); - - private class PropertySelectors - { - public readonly PropertyInfo Editor = ExpressionHelper.GetPropertyInfo(x => x.Editor); - public readonly PropertyInfo DatabaseType = ExpressionHelper.GetPropertyInfo(x => x.DatabaseType); - public readonly PropertyInfo Configuration = ExpressionHelper.GetPropertyInfo(x => x.Configuration); - } - /// [IgnoreDataMember] public IDataEditor Editor @@ -53,7 +41,7 @@ namespace Umbraco.Core.Models { // ignore if no change if (_editor.Alias == value.Alias) return; - OnPropertyChanged(Selectors.Editor); + OnPropertyChanged(nameof(Editor)); // try to map the existing configuration to the new configuration // simulate saving to db and reloading (ie go via json) @@ -73,7 +61,7 @@ namespace Umbraco.Core.Models public ValueStorageType DatabaseType { get => _databaseType; - set => SetPropertyValueAndDetectChanges(value, ref _databaseType, Selectors.DatabaseType); + set => SetPropertyValueAndDetectChanges(value, ref _databaseType, nameof(DatabaseType)); } /// @@ -124,7 +112,7 @@ namespace Umbraco.Core.Models _configurationJson = null; // it's always a change - OnPropertyChanged(Selectors.Configuration); + OnPropertyChanged(nameof(Configuration)); } } diff --git a/src/Umbraco.Core/Models/DictionaryItem.cs b/src/Umbraco.Core/Models/DictionaryItem.cs index 919f1b0a1f..c23e8f86a4 100644 --- a/src/Umbraco.Core/Models/DictionaryItem.cs +++ b/src/Umbraco.Core/Models/DictionaryItem.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Models.Entities; @@ -30,20 +29,11 @@ namespace Umbraco.Core.Models _translations = new List(); } - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo ParentIdSelector = ExpressionHelper.GetPropertyInfo(x => x.ParentId); - public readonly PropertyInfo ItemKeySelector = ExpressionHelper.GetPropertyInfo(x => x.ItemKey); - public readonly PropertyInfo TranslationsSelector = ExpressionHelper.GetPropertyInfo>(x => x.Translations); - - //Custom comparer for enumerable - public readonly DelegateEqualityComparer> DictionaryTranslationComparer = - new DelegateEqualityComparer>( - (enumerable, translations) => enumerable.UnsortedSequenceEqual(translations), - enumerable => enumerable.GetHashCode()); - } + //Custom comparer for enumerable + private static readonly DelegateEqualityComparer> DictionaryTranslationComparer = + new DelegateEqualityComparer>( + (enumerable, translations) => enumerable.UnsortedSequenceEqual(translations), + enumerable => enumerable.GetHashCode()); /// /// Gets or Sets the Parent Id of the Dictionary Item @@ -52,7 +42,7 @@ namespace Umbraco.Core.Models public Guid? ParentId { get { return _parentId; } - set { SetPropertyValueAndDetectChanges(value, ref _parentId, Ps.Value.ParentIdSelector); } + set { SetPropertyValueAndDetectChanges(value, ref _parentId, nameof(ParentId)); } } /// @@ -62,7 +52,7 @@ namespace Umbraco.Core.Models public string ItemKey { get { return _itemKey; } - set { SetPropertyValueAndDetectChanges(value, ref _itemKey, Ps.Value.ItemKeySelector); } + set { SetPropertyValueAndDetectChanges(value, ref _itemKey, nameof(ItemKey)); } } /// @@ -84,8 +74,8 @@ namespace Umbraco.Core.Models } } - SetPropertyValueAndDetectChanges(asArray, ref _translations, Ps.Value.TranslationsSelector, - Ps.Value.DictionaryTranslationComparer); + SetPropertyValueAndDetectChanges(asArray, ref _translations, nameof(Translations), + DictionaryTranslationComparer); } } } diff --git a/src/Umbraco.Core/Models/DictionaryTranslation.cs b/src/Umbraco.Core/Models/DictionaryTranslation.cs index c3b5a8a3b2..afb4063b97 100644 --- a/src/Umbraco.Core/Models/DictionaryTranslation.cs +++ b/src/Umbraco.Core/Models/DictionaryTranslation.cs @@ -1,8 +1,6 @@ using System; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Models.Entities; -using Umbraco.Core.Persistence.Mappers; namespace Umbraco.Core.Models { @@ -50,14 +48,6 @@ namespace Umbraco.Core.Models Key = uniqueId; } - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo LanguageSelector = ExpressionHelper.GetPropertyInfo(x => x.Language); - public readonly PropertyInfo ValueSelector = ExpressionHelper.GetPropertyInfo(x => x.Value); - } - /// /// Gets or sets the for the translation /// @@ -84,7 +74,7 @@ namespace Umbraco.Core.Models } set { - SetPropertyValueAndDetectChanges(value, ref _language, Ps.Value.LanguageSelector); + SetPropertyValueAndDetectChanges(value, ref _language, nameof(Language)); _languageId = _language == null ? -1 : _language.Id; } } @@ -101,7 +91,7 @@ namespace Umbraco.Core.Models public string Value { get { return _value; } - set { SetPropertyValueAndDetectChanges(value, ref _value, Ps.Value.ValueSelector); } + set { SetPropertyValueAndDetectChanges(value, ref _value, nameof(Value)); } } protected override void PerformDeepClone(object clone) diff --git a/src/Umbraco.Core/Models/Entities/BeingDirty.cs b/src/Umbraco.Core/Models/Entities/BeingDirty.cs index ec447a62dc..92b4ab5c4b 100644 --- a/src/Umbraco.Core/Models/Entities/BeingDirty.cs +++ b/src/Umbraco.Core/Models/Entities/BeingDirty.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Reflection; namespace Umbraco.Core.Models.Entities { @@ -19,19 +18,19 @@ namespace Umbraco.Core.Models.Entities /// The type of the value. /// The new value. /// A reference to the value to set. - /// The property selector. + /// The property name. /// A comparer to compare property values. - public new void SetPropertyValueAndDetectChanges(T value, ref T valueRef, PropertyInfo propertySelector, IEqualityComparer comparer = null) + public new void SetPropertyValueAndDetectChanges(T value, ref T valueRef, string propertyName, IEqualityComparer comparer = null) { - base.SetPropertyValueAndDetectChanges(value, ref valueRef, propertySelector, comparer); + base.SetPropertyValueAndDetectChanges(value, ref valueRef, propertyName, comparer); } /// /// Registers that a property has changed. /// - public new void OnPropertyChanged(PropertyInfo propertySelector) + public new void OnPropertyChanged(string propertyName) { - base.OnPropertyChanged(propertySelector); + base.OnPropertyChanged(propertyName); } } } diff --git a/src/Umbraco.Core/Models/Entities/BeingDirtyBase.cs b/src/Umbraco.Core/Models/Entities/BeingDirtyBase.cs index 711b7c9b9f..a598ba1b3d 100644 --- a/src/Umbraco.Core/Models/Entities/BeingDirtyBase.cs +++ b/src/Umbraco.Core/Models/Entities/BeingDirtyBase.cs @@ -3,7 +3,6 @@ using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Linq; -using System.Reflection; using System.Runtime.Serialization; namespace Umbraco.Core.Models.Entities @@ -108,7 +107,7 @@ namespace Umbraco.Core.Models.Entities /// /// Registers that a property has changed. /// - protected virtual void OnPropertyChanged(PropertyInfo propertyInfo) + protected virtual void OnPropertyChanged(string propertyName) { if (_withChanges == false) return; @@ -116,9 +115,9 @@ namespace Umbraco.Core.Models.Entities if (_currentChanges == null) _currentChanges = new Dictionary(); - _currentChanges[propertyInfo.Name] = true; + _currentChanges[propertyName] = true; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyInfo.Name)); + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } /// @@ -143,9 +142,9 @@ namespace Umbraco.Core.Models.Entities /// The type of the value. /// The new value. /// A reference to the value to set. - /// The property selector. + /// The property name. /// A comparer to compare property values. - protected void SetPropertyValueAndDetectChanges(T value, ref T valueRef, PropertyInfo propertySelector, IEqualityComparer comparer = null) + protected void SetPropertyValueAndDetectChanges(T value, ref T valueRef, string propertyName, IEqualityComparer comparer = null) { if (comparer == null) { @@ -165,7 +164,7 @@ namespace Umbraco.Core.Models.Entities // handle change if (changed) - OnPropertyChanged(propertySelector); + OnPropertyChanged(propertyName); } /// @@ -174,17 +173,17 @@ namespace Umbraco.Core.Models.Entities /// The type of the value. /// The new value. /// The original value. - /// The property selector. + /// The property name. /// A comparer to compare property values. /// A value indicating whether we know values have changed and no comparison is required. - protected void DetectChanges(T value, T orig, PropertyInfo propertySelector, IEqualityComparer comparer, bool changed) + protected void DetectChanges(T value, T orig, string propertyName, IEqualityComparer comparer, bool changed) { // compare values changed = _withChanges && (changed || !comparer.Equals(orig, value)); // handle change if (changed) - OnPropertyChanged(propertySelector); + OnPropertyChanged(propertyName); } #endregion diff --git a/src/Umbraco.Core/Models/Entities/EntityBase.cs b/src/Umbraco.Core/Models/Entities/EntityBase.cs index 6c9bf3d711..43837fa776 100644 --- a/src/Umbraco.Core/Models/Entities/EntityBase.cs +++ b/src/Umbraco.Core/Models/Entities/EntityBase.cs @@ -1,6 +1,5 @@ using System; using System.Diagnostics; -using System.Reflection; using System.Runtime.Serialization; namespace Umbraco.Core.Models.Entities @@ -17,23 +16,12 @@ namespace Umbraco.Core.Models.Entities public Guid InstanceId = Guid.NewGuid(); #endif - private static readonly Lazy Ps = new Lazy(); - private bool _hasIdentity; private int _id; private Guid _key; private DateTime _createDate; private DateTime _updateDate; - // ReSharper disable once ClassNeverInstantiated.Local - private class PropertySelectors - { - public readonly PropertyInfo IdSelector = ExpressionHelper.GetPropertyInfo(x => x.Id); - public readonly PropertyInfo KeySelector = ExpressionHelper.GetPropertyInfo(x => x.Key); - public readonly PropertyInfo CreateDateSelector = ExpressionHelper.GetPropertyInfo(x => x.CreateDate); - public readonly PropertyInfo UpdateDateSelector = ExpressionHelper.GetPropertyInfo(x => x.UpdateDate); - } - /// [DataMember] public int Id @@ -41,7 +29,7 @@ namespace Umbraco.Core.Models.Entities get => _id; set { - SetPropertyValueAndDetectChanges(value, ref _id, Ps.Value.IdSelector); + SetPropertyValueAndDetectChanges(value, ref _id, nameof(Id)); _hasIdentity = value != 0; } } @@ -57,7 +45,7 @@ namespace Umbraco.Core.Models.Entities _key = Guid.NewGuid(); return _key; } - set => SetPropertyValueAndDetectChanges(value, ref _key, Ps.Value.KeySelector); + set => SetPropertyValueAndDetectChanges(value, ref _key, nameof(Key)); } /// @@ -65,7 +53,7 @@ namespace Umbraco.Core.Models.Entities public DateTime CreateDate { get => _createDate; - set => SetPropertyValueAndDetectChanges(value, ref _createDate, Ps.Value.CreateDateSelector); + set => SetPropertyValueAndDetectChanges(value, ref _createDate, nameof(CreateDate)); } /// @@ -73,7 +61,7 @@ namespace Umbraco.Core.Models.Entities public DateTime UpdateDate { get => _updateDate; - set => SetPropertyValueAndDetectChanges(value, ref _updateDate, Ps.Value.UpdateDateSelector); + set => SetPropertyValueAndDetectChanges(value, ref _updateDate, nameof(UpdateDate)); } /// diff --git a/src/Umbraco.Core/Models/Entities/TreeEntityBase.cs b/src/Umbraco.Core/Models/Entities/TreeEntityBase.cs index 60e06c4977..937d7ab0fc 100644 --- a/src/Umbraco.Core/Models/Entities/TreeEntityBase.cs +++ b/src/Umbraco.Core/Models/Entities/TreeEntityBase.cs @@ -1,5 +1,4 @@ using System; -using System.Reflection; using System.Runtime.Serialization; namespace Umbraco.Core.Models.Entities @@ -9,9 +8,6 @@ namespace Umbraco.Core.Models.Entities /// public abstract class TreeEntityBase : EntityBase, ITreeEntity { - private static PropertySelectors _selectors; - private static PropertySelectors Selectors => _selectors ?? (_selectors = new PropertySelectors()); - private string _name; private int _creatorId; private int _parentId; @@ -22,23 +18,12 @@ namespace Umbraco.Core.Models.Entities private int _sortOrder; private bool _trashed; - private class PropertySelectors - { - public readonly PropertyInfo Name = ExpressionHelper.GetPropertyInfo(x => x.Name); - public readonly PropertyInfo CreatorId = ExpressionHelper.GetPropertyInfo(x => x.CreatorId); - public readonly PropertyInfo ParentId = ExpressionHelper.GetPropertyInfo(x => x.ParentId); - public readonly PropertyInfo Level = ExpressionHelper.GetPropertyInfo(x => x.Level); - public readonly PropertyInfo Path = ExpressionHelper.GetPropertyInfo(x => x.Path); - public readonly PropertyInfo SortOrder = ExpressionHelper.GetPropertyInfo(x => x.SortOrder); - public readonly PropertyInfo Trashed = ExpressionHelper.GetPropertyInfo(x => x.Trashed); - } - /// [DataMember] public string Name { get => _name; - set => SetPropertyValueAndDetectChanges(value, ref _name, Selectors.Name); + set => SetPropertyValueAndDetectChanges(value, ref _name, nameof(Name)); } /// @@ -46,7 +31,7 @@ namespace Umbraco.Core.Models.Entities public int CreatorId { get => _creatorId; - set => SetPropertyValueAndDetectChanges(value, ref _creatorId, Selectors.CreatorId); + set => SetPropertyValueAndDetectChanges(value, ref _creatorId, nameof(CreatorId)); } /// @@ -72,7 +57,7 @@ namespace Umbraco.Core.Models.Entities { if (value == 0) throw new ArgumentException("Value cannot be zero.", nameof(value)); - SetPropertyValueAndDetectChanges(value, ref _parentId, Selectors.ParentId); + SetPropertyValueAndDetectChanges(value, ref _parentId, nameof(ParentId)); _hasParentId = true; _parent = null; } @@ -83,7 +68,7 @@ namespace Umbraco.Core.Models.Entities { _hasParentId = false; _parent = parent; - OnPropertyChanged(Selectors.ParentId); + OnPropertyChanged(nameof(ParentId)); } /// @@ -91,7 +76,7 @@ namespace Umbraco.Core.Models.Entities public int Level { get => _level; - set => SetPropertyValueAndDetectChanges(value, ref _level, Selectors.Level); + set => SetPropertyValueAndDetectChanges(value, ref _level, nameof(Level)); } /// @@ -99,7 +84,7 @@ namespace Umbraco.Core.Models.Entities public string Path { get => _path; - set => SetPropertyValueAndDetectChanges(value, ref _path, Selectors.Path); + set => SetPropertyValueAndDetectChanges(value, ref _path, nameof(Path)); } /// @@ -107,7 +92,7 @@ namespace Umbraco.Core.Models.Entities public int SortOrder { get => _sortOrder; - set => SetPropertyValueAndDetectChanges(value, ref _sortOrder, Selectors.SortOrder); + set => SetPropertyValueAndDetectChanges(value, ref _sortOrder, nameof(SortOrder)); } /// @@ -115,7 +100,7 @@ namespace Umbraco.Core.Models.Entities public bool Trashed { get => _trashed; - set => SetPropertyValueAndDetectChanges(value, ref _trashed, Selectors.Trashed); + set => SetPropertyValueAndDetectChanges(value, ref _trashed, nameof(Trashed)); } } } diff --git a/src/Umbraco.Core/Models/File.cs b/src/Umbraco.Core/Models/File.cs index 2f8e021f4c..845da4d053 100644 --- a/src/Umbraco.Core/Models/File.cs +++ b/src/Umbraco.Core/Models/File.cs @@ -1,9 +1,5 @@ using System; -using System.IO; -using System.Reflection; using System.Runtime.Serialization; -using System.Text; -using Umbraco.Core.IO; using Umbraco.Core.Models.Entities; namespace Umbraco.Core.Models @@ -33,14 +29,6 @@ namespace Umbraco.Core.Models _content = getFileContent != null ? null : string.Empty; } - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo ContentSelector = ExpressionHelper.GetPropertyInfo(x => x.Content); - public readonly PropertyInfo PathSelector = ExpressionHelper.GetPropertyInfo(x => x.Path); - } - private string _alias; private string _name; @@ -96,7 +84,7 @@ namespace Umbraco.Core.Models _alias = null; _name = null; - SetPropertyValueAndDetectChanges(SanitizePath(value), ref _path, Ps.Value.PathSelector); + SetPropertyValueAndDetectChanges(SanitizePath(value), ref _path, nameof(Path)); } } @@ -138,7 +126,7 @@ namespace Umbraco.Core.Models { SetPropertyValueAndDetectChanges( value ?? string.Empty, // cannot set to null - ref _content, Ps.Value.ContentSelector); + ref _content, nameof(Content)); } } diff --git a/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs b/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs index f5c21a3a74..0eb53428d1 100644 --- a/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs +++ b/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs @@ -3,21 +3,14 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Linq; -using System.Reflection; -using System.Security.Claims; -using System.Threading.Tasks; using Umbraco.Core.Composing; -using Umbraco.Core.Configuration; using Umbraco.Core.Models.Entities; using Umbraco.Core.Models.Membership; -using Umbraco.Core.Security; namespace Umbraco.Core.Models.Identity { public class BackOfficeIdentityUser : IdentityUser, IdentityUserClaim>, IRememberBeingDirty { - private static readonly Lazy Ps = new Lazy(); - private string _email; private string _userName; private int _id; @@ -118,7 +111,7 @@ namespace Umbraco.Core.Models.Identity public override string Email { get => _email; - set => _beingDirty.SetPropertyValueAndDetectChanges(value, ref _email, Ps.Value.EmailSelector); + set => _beingDirty.SetPropertyValueAndDetectChanges(value, ref _email, nameof(Email)); } /// @@ -127,7 +120,7 @@ namespace Umbraco.Core.Models.Identity public override string UserName { get => _userName; - set => _beingDirty.SetPropertyValueAndDetectChanges(value, ref _userName, Ps.Value.UserNameSelector); + set => _beingDirty.SetPropertyValueAndDetectChanges(value, ref _userName, nameof(UserName)); } /// @@ -136,7 +129,7 @@ namespace Umbraco.Core.Models.Identity public override DateTime? LastPasswordChangeDateUtc { get { return _lastPasswordChangeDateUtc; } - set { _beingDirty.SetPropertyValueAndDetectChanges(value, ref _lastPasswordChangeDateUtc, Ps.Value.LastPasswordChangeDateUtcSelector); } + set { _beingDirty.SetPropertyValueAndDetectChanges(value, ref _lastPasswordChangeDateUtc, nameof(LastPasswordChangeDateUtc)); } } /// @@ -145,7 +138,7 @@ namespace Umbraco.Core.Models.Identity public override DateTime? LastLoginDateUtc { get => _lastLoginDateUtc; - set => _beingDirty.SetPropertyValueAndDetectChanges(value, ref _lastLoginDateUtc, Ps.Value.LastLoginDateUtcSelector); + set => _beingDirty.SetPropertyValueAndDetectChanges(value, ref _lastLoginDateUtc, nameof(LastLoginDateUtc)); } /// @@ -154,7 +147,7 @@ namespace Umbraco.Core.Models.Identity public override bool EmailConfirmed { get => _emailConfirmed; - set => _beingDirty.SetPropertyValueAndDetectChanges(value, ref _emailConfirmed, Ps.Value.EmailConfirmedSelector); + set => _beingDirty.SetPropertyValueAndDetectChanges(value, ref _emailConfirmed, nameof(EmailConfirmed)); } /// @@ -163,7 +156,7 @@ namespace Umbraco.Core.Models.Identity public string Name { get => _name; - set => _beingDirty.SetPropertyValueAndDetectChanges(value, ref _name, Ps.Value.NameSelector); + set => _beingDirty.SetPropertyValueAndDetectChanges(value, ref _name, nameof(Name)); } /// @@ -172,7 +165,7 @@ namespace Umbraco.Core.Models.Identity public override int AccessFailedCount { get => _accessFailedCount; - set => _beingDirty.SetPropertyValueAndDetectChanges(value, ref _accessFailedCount, Ps.Value.AccessFailedCountSelector); + set => _beingDirty.SetPropertyValueAndDetectChanges(value, ref _accessFailedCount, nameof(AccessFailedCount)); } /// @@ -181,7 +174,7 @@ namespace Umbraco.Core.Models.Identity public override string PasswordHash { get => _passwordHash; - set => _beingDirty.SetPropertyValueAndDetectChanges(value, ref _passwordHash, Ps.Value.PasswordHashSelector); + set => _beingDirty.SetPropertyValueAndDetectChanges(value, ref _passwordHash, nameof(PasswordHash)); } @@ -194,7 +187,7 @@ namespace Umbraco.Core.Models.Identity set { if (value == null) value = new int[0]; - _beingDirty.SetPropertyValueAndDetectChanges(value, ref _startContentIds, Ps.Value.StartContentIdsSelector, Ps.Value.StartIdsComparer); + _beingDirty.SetPropertyValueAndDetectChanges(value, ref _startContentIds, nameof(StartContentIds), StartIdsComparer); } } @@ -207,7 +200,7 @@ namespace Umbraco.Core.Models.Identity set { if (value == null) value = new int[0]; - _beingDirty.SetPropertyValueAndDetectChanges(value, ref _startMediaIds, Ps.Value.StartMediaIdsSelector, Ps.Value.StartIdsComparer); + _beingDirty.SetPropertyValueAndDetectChanges(value, ref _startMediaIds, nameof(StartMediaIds), StartIdsComparer); } } @@ -222,7 +215,7 @@ namespace Umbraco.Core.Models.Identity public string Culture { get => _culture; - set => _beingDirty.SetPropertyValueAndDetectChanges(value, ref _culture, Ps.Value.CultureSelector); + set => _beingDirty.SetPropertyValueAndDetectChanges(value, ref _culture, nameof(Culture)); } public IReadOnlyUserGroup[] Groups @@ -246,7 +239,7 @@ namespace Umbraco.Core.Models.Identity } _roles.CollectionChanged += _roles_CollectionChanged; - _beingDirty.SetPropertyValueAndDetectChanges(value, ref _groups, Ps.Value.GroupsSelector, Ps.Value.GroupsComparer); + _beingDirty.SetPropertyValueAndDetectChanges(value, ref _groups, nameof(Groups), GroupsComparer); } } @@ -302,12 +295,12 @@ namespace Umbraco.Core.Models.Identity void Logins_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { - _beingDirty.OnPropertyChanged(Ps.Value.LoginsSelector); + _beingDirty.OnPropertyChanged(nameof(Logins)); } private void _roles_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { - _beingDirty.OnPropertyChanged(Ps.Value.RolesSelector); + _beingDirty.OnPropertyChanged(nameof(Roles)); } private readonly ObservableCollection> _roles; @@ -416,33 +409,13 @@ namespace Umbraco.Core.Models.Identity #endregion - // ReSharper disable once ClassNeverInstantiated.Local - private class PropertySelectors - { - public readonly PropertyInfo EmailSelector = ExpressionHelper.GetPropertyInfo(x => x.Email); - public readonly PropertyInfo UserNameSelector = ExpressionHelper.GetPropertyInfo(x => x.UserName); - public readonly PropertyInfo LastLoginDateUtcSelector = ExpressionHelper.GetPropertyInfo(x => x.LastLoginDateUtc); - public readonly PropertyInfo LastPasswordChangeDateUtcSelector = ExpressionHelper.GetPropertyInfo(x => x.LastPasswordChangeDateUtc); - public readonly PropertyInfo EmailConfirmedSelector = ExpressionHelper.GetPropertyInfo(x => x.EmailConfirmed); - public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo(x => x.Name); - public readonly PropertyInfo AccessFailedCountSelector = ExpressionHelper.GetPropertyInfo(x => x.AccessFailedCount); - public readonly PropertyInfo PasswordHashSelector = ExpressionHelper.GetPropertyInfo(x => x.PasswordHash); - public readonly PropertyInfo CultureSelector = ExpressionHelper.GetPropertyInfo(x => x.Culture); - public readonly PropertyInfo StartMediaIdsSelector = ExpressionHelper.GetPropertyInfo(x => x.StartMediaIds); - public readonly PropertyInfo StartContentIdsSelector = ExpressionHelper.GetPropertyInfo(x => x.StartContentIds); - public readonly PropertyInfo GroupsSelector = ExpressionHelper.GetPropertyInfo(x => x.Groups); - public readonly PropertyInfo LoginsSelector = ExpressionHelper.GetPropertyInfo>(x => x.Logins); - public readonly PropertyInfo RolesSelector = ExpressionHelper.GetPropertyInfo>>(x => x.Roles); - - //Custom comparer for enumerables - public readonly DelegateEqualityComparer GroupsComparer = new DelegateEqualityComparer( - (groups, enumerable) => groups.Select(x => x.Alias).UnsortedSequenceEqual(enumerable.Select(x => x.Alias)), - groups => groups.GetHashCode()); - public readonly DelegateEqualityComparer StartIdsComparer = new DelegateEqualityComparer( - (groups, enumerable) => groups.UnsortedSequenceEqual(enumerable), - groups => groups.GetHashCode()); - - } + //Custom comparer for enumerables + private static readonly DelegateEqualityComparer GroupsComparer = new DelegateEqualityComparer( + (groups, enumerable) => groups.Select(x => x.Alias).UnsortedSequenceEqual(enumerable.Select(x => x.Alias)), + groups => groups.GetHashCode()); + private static readonly DelegateEqualityComparer StartIdsComparer = new DelegateEqualityComparer( + (groups, enumerable) => groups.UnsortedSequenceEqual(enumerable), + groups => groups.GetHashCode()); } } diff --git a/src/Umbraco.Core/Models/Language.cs b/src/Umbraco.Core/Models/Language.cs index b02eb4805c..7d5fda3e06 100644 --- a/src/Umbraco.Core/Models/Language.cs +++ b/src/Umbraco.Core/Models/Language.cs @@ -1,7 +1,5 @@ using System; using System.Globalization; -using System.Linq; -using System.Reflection; using System.Runtime.Serialization; using System.Threading; using Umbraco.Core.Configuration; @@ -16,8 +14,6 @@ namespace Umbraco.Core.Models [DataContract(IsReference = true)] public class Language : EntityBase, ILanguage { - private static readonly Lazy Ps = new Lazy(); - private string _isoCode; private string _cultureName; private bool _isDefaultVariantLanguage; @@ -29,22 +25,12 @@ namespace Umbraco.Core.Models IsoCode = isoCode; } - // ReSharper disable once ClassNeverInstantiated.Local - private class PropertySelectors - { - public readonly PropertyInfo IsoCodeSelector = ExpressionHelper.GetPropertyInfo(x => x.IsoCode); - public readonly PropertyInfo CultureNameSelector = ExpressionHelper.GetPropertyInfo(x => x.CultureName); - public readonly PropertyInfo IsDefaultVariantLanguageSelector = ExpressionHelper.GetPropertyInfo(x => x.IsDefault); - public readonly PropertyInfo MandatorySelector = ExpressionHelper.GetPropertyInfo(x => x.IsMandatory); - public readonly PropertyInfo FallbackLanguageSelector = ExpressionHelper.GetPropertyInfo(x => x.FallbackLanguageId); - } - /// [DataMember] public string IsoCode { get => _isoCode; - set => SetPropertyValueAndDetectChanges(value, ref _isoCode, Ps.Value.IsoCodeSelector); + set => SetPropertyValueAndDetectChanges(value, ref _isoCode, nameof(IsoCode)); } /// @@ -102,7 +88,7 @@ namespace Umbraco.Core.Models } } - set => SetPropertyValueAndDetectChanges(value, ref _cultureName, Ps.Value.CultureNameSelector); + set => SetPropertyValueAndDetectChanges(value, ref _cultureName, nameof(CultureName)); } /// @@ -113,21 +99,21 @@ namespace Umbraco.Core.Models public bool IsDefault { get => _isDefaultVariantLanguage; - set => SetPropertyValueAndDetectChanges(value, ref _isDefaultVariantLanguage, Ps.Value.IsDefaultVariantLanguageSelector); + set => SetPropertyValueAndDetectChanges(value, ref _isDefaultVariantLanguage, nameof(IsDefault)); } /// public bool IsMandatory { get => _mandatory; - set => SetPropertyValueAndDetectChanges(value, ref _mandatory, Ps.Value.MandatorySelector); + set => SetPropertyValueAndDetectChanges(value, ref _mandatory, nameof(IsMandatory)); } /// public int? FallbackLanguageId { get => _fallbackLanguageId; - set => SetPropertyValueAndDetectChanges(value, ref _fallbackLanguageId, Ps.Value.FallbackLanguageSelector); + set => SetPropertyValueAndDetectChanges(value, ref _fallbackLanguageId, nameof(FallbackLanguageId)); } } } diff --git a/src/Umbraco.Core/Models/Macro.cs b/src/Umbraco.Core/Models/Macro.cs index 5ef49305ac..bc71d3dc2b 100644 --- a/src/Umbraco.Core/Models/Macro.cs +++ b/src/Umbraco.Core/Models/Macro.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; using System.Linq; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Models.Entities; using Umbraco.Core.Strings; @@ -99,25 +98,9 @@ namespace Umbraco.Core.Models private List _addedProperties; private List _removedProperties; - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo(x => x.Alias); - public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo(x => x.Name); - public readonly PropertyInfo UseInEditorSelector = ExpressionHelper.GetPropertyInfo(x => x.UseInEditor); - public readonly PropertyInfo CacheDurationSelector = ExpressionHelper.GetPropertyInfo(x => x.CacheDuration); - public readonly PropertyInfo CacheByPageSelector = ExpressionHelper.GetPropertyInfo(x => x.CacheByPage); - public readonly PropertyInfo CacheByMemberSelector = ExpressionHelper.GetPropertyInfo(x => x.CacheByMember); - public readonly PropertyInfo DontRenderSelector = ExpressionHelper.GetPropertyInfo(x => x.DontRender); - public readonly PropertyInfo ScriptPathSelector = ExpressionHelper.GetPropertyInfo(x => x.MacroSource); - public readonly PropertyInfo MacroTypeSelector = ExpressionHelper.GetPropertyInfo(x => x.MacroType); - public readonly PropertyInfo PropertiesSelector = ExpressionHelper.GetPropertyInfo(x => x.Properties); - } - void PropertiesChanged(object sender, NotifyCollectionChangedEventArgs e) { - OnPropertyChanged(Ps.Value.PropertiesSelector); + OnPropertyChanged(nameof(Properties)); if (e.Action == NotifyCollectionChangedAction.Add) { @@ -155,7 +138,7 @@ namespace Umbraco.Core.Models /// void PropertyDataChanged(object sender, PropertyChangedEventArgs e) { - OnPropertyChanged(Ps.Value.PropertiesSelector); + OnPropertyChanged(nameof(Properties)); } public override void ResetDirtyProperties(bool rememberDirty) @@ -172,18 +155,12 @@ namespace Umbraco.Core.Models /// /// Used internally to check if we need to add a section in the repository to the db /// - internal IEnumerable AddedProperties - { - get { return _addedProperties; } - } + internal IEnumerable AddedProperties => _addedProperties; /// /// Used internally to check if we need to remove a section in the repository to the db /// - internal IEnumerable RemovedProperties - { - get { return _removedProperties; } - } + internal IEnumerable RemovedProperties => _removedProperties; /// /// Gets or sets the alias of the Macro @@ -191,8 +168,8 @@ namespace Umbraco.Core.Models [DataMember] public string Alias { - get { return _alias; } - set { SetPropertyValueAndDetectChanges(value.ToCleanString(CleanStringType.Alias), ref _alias, Ps.Value.AliasSelector); } + get => _alias; + set => SetPropertyValueAndDetectChanges(value.ToCleanString(CleanStringType.Alias), ref _alias, nameof(Alias)); } /// @@ -201,8 +178,8 @@ namespace Umbraco.Core.Models [DataMember] public string Name { - get { return _name; } - set { SetPropertyValueAndDetectChanges(value, ref _name, Ps.Value.NameSelector); } + get => _name; + set => SetPropertyValueAndDetectChanges(value, ref _name, nameof(Name)); } /// @@ -211,8 +188,8 @@ namespace Umbraco.Core.Models [DataMember] public bool UseInEditor { - get { return _useInEditor; } - set { SetPropertyValueAndDetectChanges(value, ref _useInEditor, Ps.Value.UseInEditorSelector); } + get => _useInEditor; + set => SetPropertyValueAndDetectChanges(value, ref _useInEditor, nameof(UseInEditor)); } /// @@ -221,8 +198,8 @@ namespace Umbraco.Core.Models [DataMember] public int CacheDuration { - get { return _cacheDuration; } - set { SetPropertyValueAndDetectChanges(value, ref _cacheDuration, Ps.Value.CacheDurationSelector); } + get => _cacheDuration; + set => SetPropertyValueAndDetectChanges(value, ref _cacheDuration, nameof(CacheDuration)); } /// @@ -231,8 +208,8 @@ namespace Umbraco.Core.Models [DataMember] public bool CacheByPage { - get { return _cacheByPage; } - set { SetPropertyValueAndDetectChanges(value, ref _cacheByPage, Ps.Value.CacheByPageSelector); } + get => _cacheByPage; + set => SetPropertyValueAndDetectChanges(value, ref _cacheByPage, nameof(CacheByPage)); } /// @@ -241,8 +218,8 @@ namespace Umbraco.Core.Models [DataMember] public bool CacheByMember { - get { return _cacheByMember; } - set { SetPropertyValueAndDetectChanges(value, ref _cacheByMember, Ps.Value.CacheByMemberSelector); } + get => _cacheByMember; + set => SetPropertyValueAndDetectChanges(value, ref _cacheByMember, nameof(CacheByMember)); } /// @@ -251,8 +228,8 @@ namespace Umbraco.Core.Models [DataMember] public bool DontRender { - get { return _dontRender; } - set { SetPropertyValueAndDetectChanges(value, ref _dontRender, Ps.Value.DontRenderSelector); } + get => _dontRender; + set => SetPropertyValueAndDetectChanges(value, ref _dontRender, nameof(DontRender)); } /// @@ -261,8 +238,8 @@ namespace Umbraco.Core.Models [DataMember] public string MacroSource { - get { return _macroSource; } - set { SetPropertyValueAndDetectChanges(value, ref _macroSource, Ps.Value.ScriptPathSelector); } + get => _macroSource; + set => SetPropertyValueAndDetectChanges(value, ref _macroSource, nameof(MacroSource)); } /// @@ -271,18 +248,15 @@ namespace Umbraco.Core.Models [DataMember] public MacroTypes MacroType { - get { return _macroType; } - set { SetPropertyValueAndDetectChanges(value, ref _macroType, Ps.Value.MacroTypeSelector); } + get => _macroType; + set => SetPropertyValueAndDetectChanges(value, ref _macroType, nameof(MacroType)); } /// /// Gets or sets a list of Macro Properties /// [DataMember] - public MacroPropertyCollection Properties - { - get { return _properties; } - } + public MacroPropertyCollection Properties => _properties; protected override void PerformDeepClone(object clone) { diff --git a/src/Umbraco.Core/Models/MacroProperty.cs b/src/Umbraco.Core/Models/MacroProperty.cs index 380705b3d5..62ba6a7a7d 100644 --- a/src/Umbraco.Core/Models/MacroProperty.cs +++ b/src/Umbraco.Core/Models/MacroProperty.cs @@ -1,8 +1,6 @@ using System; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Models.Entities; -using Umbraco.Core.PropertyEditors; namespace Umbraco.Core.Models { @@ -59,27 +57,15 @@ namespace Umbraco.Core.Models private int _sortOrder; private int _id; private string _editorAlias; - - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo KeySelector = ExpressionHelper.GetPropertyInfo(x => x.Key); - public readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo(x => x.Alias); - public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo(x => x.Name); - public readonly PropertyInfo SortOrderSelector = ExpressionHelper.GetPropertyInfo(x => x.SortOrder); - public readonly PropertyInfo IdSelector = ExpressionHelper.GetPropertyInfo(x => x.Id); - public readonly PropertyInfo PropertyTypeSelector = ExpressionHelper.GetPropertyInfo(x => x.EditorAlias); - } - + /// /// Gets or sets the Key of the Property /// [DataMember] public Guid Key { - get { return _key; } - set { SetPropertyValueAndDetectChanges(value, ref _key, Ps.Value.KeySelector); } + get => _key; + set => SetPropertyValueAndDetectChanges(value, ref _key, nameof(Key)); } /// @@ -88,8 +74,8 @@ namespace Umbraco.Core.Models [DataMember] public int Id { - get { return _id; } - set { SetPropertyValueAndDetectChanges(value, ref _id, Ps.Value.IdSelector); } + get => _id; + set => SetPropertyValueAndDetectChanges(value, ref _id, nameof(Id)); } /// @@ -98,8 +84,8 @@ namespace Umbraco.Core.Models [DataMember] public string Alias { - get { return _alias; } - set { SetPropertyValueAndDetectChanges(value, ref _alias, Ps.Value.AliasSelector); } + get => _alias; + set => SetPropertyValueAndDetectChanges(value, ref _alias, nameof(Alias)); } /// @@ -108,8 +94,8 @@ namespace Umbraco.Core.Models [DataMember] public string Name { - get { return _name; } - set { SetPropertyValueAndDetectChanges(value, ref _name, Ps.Value.NameSelector); } + get => _name; + set => SetPropertyValueAndDetectChanges(value, ref _name, nameof(Name)); } /// @@ -118,8 +104,8 @@ namespace Umbraco.Core.Models [DataMember] public int SortOrder { - get { return _sortOrder; } - set { SetPropertyValueAndDetectChanges(value, ref _sortOrder, Ps.Value.SortOrderSelector); } + get => _sortOrder; + set => SetPropertyValueAndDetectChanges(value, ref _sortOrder, nameof(SortOrder)); } /// @@ -132,11 +118,8 @@ namespace Umbraco.Core.Models [DataMember] public string EditorAlias { - get { return _editorAlias; } - set - { - SetPropertyValueAndDetectChanges(value, ref _editorAlias, Ps.Value.PropertyTypeSelector); - } + get => _editorAlias; + set => SetPropertyValueAndDetectChanges(value, ref _editorAlias, nameof(EditorAlias)); } public object DeepClone() diff --git a/src/Umbraco.Core/Models/Member.cs b/src/Umbraco.Core/Models/Member.cs index 0ef15ee413..78d1cfafd5 100644 --- a/src/Umbraco.Core/Models/Member.cs +++ b/src/Umbraco.Core/Models/Member.cs @@ -1,13 +1,9 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Composing; using Umbraco.Core.Exceptions; using Umbraco.Core.Logging; -using Umbraco.Core.Models.Entities; namespace Umbraco.Core.Models { @@ -131,24 +127,14 @@ namespace Umbraco.Core.Models IsApproved = isApproved; } - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo UsernameSelector = ExpressionHelper.GetPropertyInfo(x => x.Username); - public readonly PropertyInfo EmailSelector = ExpressionHelper.GetPropertyInfo(x => x.Email); - public readonly PropertyInfo PasswordSelector = ExpressionHelper.GetPropertyInfo(x => x.RawPasswordValue); - public readonly PropertyInfo ProviderUserKeySelector = ExpressionHelper.GetPropertyInfo(x => x.ProviderUserKey); - } - /// /// Gets or sets the Username /// [DataMember] public string Username { - get { return _username; } - set { SetPropertyValueAndDetectChanges(value, ref _username, Ps.Value.UsernameSelector); } + get => _username; + set => SetPropertyValueAndDetectChanges(value, ref _username, nameof(Username)); } /// @@ -157,8 +143,8 @@ namespace Umbraco.Core.Models [DataMember] public string Email { - get { return _email; } - set { SetPropertyValueAndDetectChanges(value, ref _email, Ps.Value.EmailSelector); } + get => _email; + set => SetPropertyValueAndDetectChanges(value, ref _email, nameof(Email)); } /// @@ -167,7 +153,7 @@ namespace Umbraco.Core.Models [IgnoreDataMember] public string RawPasswordValue { - get { return _rawPasswordValue; } + get => _rawPasswordValue; set { if (value == null) @@ -178,7 +164,7 @@ namespace Umbraco.Core.Models } else { - SetPropertyValueAndDetectChanges(value, ref _rawPasswordValue, Ps.Value.PasswordSelector); + SetPropertyValueAndDetectChanges(value, ref _rawPasswordValue, nameof(RawPasswordValue)); } } } @@ -487,10 +473,7 @@ namespace Umbraco.Core.Models /// String alias of the default ContentType /// [DataMember] - public virtual string ContentTypeAlias - { - get { return _contentTypeAlias; } - } + public virtual string ContentTypeAlias => _contentTypeAlias; /// /// User key from the Provider. @@ -504,11 +487,8 @@ namespace Umbraco.Core.Models [DataMember] public virtual object ProviderUserKey { - get - { - return _providerUserKey; - } - set { SetPropertyValueAndDetectChanges(value, ref _providerUserKey, Ps.Value.ProviderUserKeySelector); } + get => _providerUserKey; + set => SetPropertyValueAndDetectChanges(value, ref _providerUserKey, nameof(ProviderUserKey)); } @@ -528,10 +508,7 @@ namespace Umbraco.Core.Models /// Gets the ContentType used by this content object /// [IgnoreDataMember] - public IMemberType ContentType - { - get { return _contentType; } - } + public IMemberType ContentType => _contentType; /* Internal experiment - only used for mapping queries. * Adding these to have first level properties instead of the Properties collection. diff --git a/src/Umbraco.Core/Models/MemberGroup.cs b/src/Umbraco.Core/Models/MemberGroup.cs index 0653f75ef7..8c06da418d 100644 --- a/src/Umbraco.Core/Models/MemberGroup.cs +++ b/src/Umbraco.Core/Models/MemberGroup.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Models.Entities; @@ -13,19 +12,10 @@ namespace Umbraco.Core.Models [DataContract(IsReference = true)] public class MemberGroup : EntityBase, IMemberGroup { - private static PropertySelectors _selectors; private IDictionary _additionalData; private string _name; private int _creatorId; - private static PropertySelectors Selectors => _selectors ?? (_selectors = new PropertySelectors()); - - private class PropertySelectors - { - public readonly PropertyInfo Name = ExpressionHelper.GetPropertyInfo(x => x.Name); - public readonly PropertyInfo CreatorId = ExpressionHelper.GetPropertyInfo(x => x.CreatorId); - } - /// [DataMember] [DoNotClone] @@ -49,7 +39,7 @@ namespace Umbraco.Core.Models AdditionalData["previousName"] = _name; } - SetPropertyValueAndDetectChanges(value, ref _name, Selectors.Name); + SetPropertyValueAndDetectChanges(value, ref _name, nameof(Name)); } } @@ -57,7 +47,7 @@ namespace Umbraco.Core.Models public int CreatorId { get => _creatorId; - set => SetPropertyValueAndDetectChanges(value, ref _creatorId, Selectors.CreatorId); + set => SetPropertyValueAndDetectChanges(value, ref _creatorId, nameof(CreatorId)); } } } diff --git a/src/Umbraco.Core/Models/MemberType.cs b/src/Umbraco.Core/Models/MemberType.cs index 1ce883d9a7..a6c1518446 100644 --- a/src/Umbraco.Core/Models/MemberType.cs +++ b/src/Umbraco.Core/Models/MemberType.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Reflection; using System.Runtime.Serialization; namespace Umbraco.Core.Models @@ -12,7 +11,6 @@ namespace Umbraco.Core.Models [DataContract(IsReference = true)] public class MemberType : ContentTypeCompositionBase, IMemberType { - private static readonly Lazy Ps = new Lazy(); public const bool IsPublishingConst = false; //Dictionary is divided into string: PropertyTypeAlias, Tuple: MemberCanEdit, VisibleOnProfile, PropertyTypeId @@ -46,12 +44,6 @@ namespace Umbraco.Core.Models set => throw new NotSupportedException("Variations are not supported on members."); } - // ReSharper disable once ClassNeverInstantiated.Local - private class PropertySelectors - { - public readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo(x => x.Alias); - } - /// /// The Alias of the ContentType /// @@ -74,7 +66,7 @@ namespace Umbraco.Core.Models ? value : (value == null ? string.Empty : value.ToSafeAlias()); - SetPropertyValueAndDetectChanges(newVal, ref _alias, Ps.Value.AliasSelector); + SetPropertyValueAndDetectChanges(newVal, ref _alias, nameof(Alias)); } } diff --git a/src/Umbraco.Core/Models/Membership/User.cs b/src/Umbraco.Core/Models/Membership/User.cs index 7832390b92..2fb293c349 100644 --- a/src/Umbraco.Core/Models/Membership/User.cs +++ b/src/Umbraco.Core/Models/Membership/User.cs @@ -1,14 +1,8 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Collections.Specialized; -using System.ComponentModel; using System.Linq; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Composing; -using Umbraco.Core.Configuration; -using Umbraco.Core.Logging; using Umbraco.Core.Models.Entities; namespace Umbraco.Core.Models.Membership @@ -123,123 +117,92 @@ namespace Umbraco.Core.Models.Membership private IDictionary _additionalData; private object _additionalDataLock = new object(); - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo FailedPasswordAttemptsSelector = ExpressionHelper.GetPropertyInfo(x => x.FailedPasswordAttempts); - public readonly PropertyInfo LastLockoutDateSelector = ExpressionHelper.GetPropertyInfo(x => x.LastLockoutDate); - public readonly PropertyInfo LastLoginDateSelector = ExpressionHelper.GetPropertyInfo(x => x.LastLoginDate); - public readonly PropertyInfo LastPasswordChangeDateSelector = ExpressionHelper.GetPropertyInfo(x => x.LastPasswordChangeDate); - - public readonly PropertyInfo SecurityStampSelector = ExpressionHelper.GetPropertyInfo(x => x.SecurityStamp); - public readonly PropertyInfo AvatarSelector = ExpressionHelper.GetPropertyInfo(x => x.Avatar); - public readonly PropertyInfo TourDataSelector = ExpressionHelper.GetPropertyInfo(x => x.TourData); - public readonly PropertyInfo SessionTimeoutSelector = ExpressionHelper.GetPropertyInfo(x => x.SessionTimeout); - public readonly PropertyInfo StartContentIdSelector = ExpressionHelper.GetPropertyInfo(x => x.StartContentIds); - public readonly PropertyInfo StartMediaIdSelector = ExpressionHelper.GetPropertyInfo(x => x.StartMediaIds); - public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo(x => x.Name); - - public readonly PropertyInfo UsernameSelector = ExpressionHelper.GetPropertyInfo(x => x.Username); - public readonly PropertyInfo EmailSelector = ExpressionHelper.GetPropertyInfo(x => x.Email); - public readonly PropertyInfo PasswordSelector = ExpressionHelper.GetPropertyInfo(x => x.RawPasswordValue); - public readonly PropertyInfo IsLockedOutSelector = ExpressionHelper.GetPropertyInfo(x => x.IsLockedOut); - public readonly PropertyInfo IsApprovedSelector = ExpressionHelper.GetPropertyInfo(x => x.IsApproved); - public readonly PropertyInfo LanguageSelector = ExpressionHelper.GetPropertyInfo(x => x.Language); - public readonly PropertyInfo EmailConfirmedDateSelector = ExpressionHelper.GetPropertyInfo(x => x.EmailConfirmedDate); - public readonly PropertyInfo InvitedDateSelector = ExpressionHelper.GetPropertyInfo(x => x.InvitedDate); - - public readonly PropertyInfo DefaultToLiveEditingSelector = ExpressionHelper.GetPropertyInfo(x => x.DefaultToLiveEditing); - - public readonly PropertyInfo UserGroupsSelector = ExpressionHelper.GetPropertyInfo>(x => x.Groups); - - //Custom comparer for enumerable - public readonly DelegateEqualityComparer> IntegerEnumerableComparer = - new DelegateEqualityComparer>( - (enum1, enum2) => enum1.UnsortedSequenceEqual(enum2), - enum1 => enum1.GetHashCode()); - } + //Custom comparer for enumerable + private static readonly DelegateEqualityComparer> IntegerEnumerableComparer = + new DelegateEqualityComparer>( + (enum1, enum2) => enum1.UnsortedSequenceEqual(enum2), + enum1 => enum1.GetHashCode()); #region Implementation of IMembershipUser [IgnoreDataMember] public object ProviderUserKey { - get { return Id; } - set { throw new NotSupportedException("Cannot set the provider user key for a user"); } + get => Id; + set => throw new NotSupportedException("Cannot set the provider user key for a user"); } [DataMember] public DateTime? EmailConfirmedDate { - get { return _emailConfirmedDate; } - set { SetPropertyValueAndDetectChanges(value, ref _emailConfirmedDate, Ps.Value.EmailConfirmedDateSelector); } + get => _emailConfirmedDate; + set => SetPropertyValueAndDetectChanges(value, ref _emailConfirmedDate, nameof(EmailConfirmedDate)); } [DataMember] public DateTime? InvitedDate { - get { return _invitedDate; } - set { SetPropertyValueAndDetectChanges(value, ref _invitedDate, Ps.Value.InvitedDateSelector); } + get => _invitedDate; + set => SetPropertyValueAndDetectChanges(value, ref _invitedDate, nameof(InvitedDate)); } [DataMember] public string Username { - get { return _username; } - set { SetPropertyValueAndDetectChanges(value, ref _username, Ps.Value.UsernameSelector); } + get => _username; + set => SetPropertyValueAndDetectChanges(value, ref _username, nameof(Username)); } [DataMember] public string Email { - get { return _email; } - set { SetPropertyValueAndDetectChanges(value, ref _email, Ps.Value.EmailSelector); } + get => _email; + set => SetPropertyValueAndDetectChanges(value, ref _email, nameof(Email)); } [DataMember] public string RawPasswordValue { - get { return _rawPasswordValue; } - set { SetPropertyValueAndDetectChanges(value, ref _rawPasswordValue, Ps.Value.PasswordSelector); } + get => _rawPasswordValue; + set => SetPropertyValueAndDetectChanges(value, ref _rawPasswordValue, nameof(RawPasswordValue)); } [DataMember] public bool IsApproved { - get { return _isApproved; } - set { SetPropertyValueAndDetectChanges(value, ref _isApproved, Ps.Value.IsApprovedSelector); } + get => _isApproved; + set => SetPropertyValueAndDetectChanges(value, ref _isApproved, nameof(IsApproved)); } [IgnoreDataMember] public bool IsLockedOut { - get { return _isLockedOut; } - set { SetPropertyValueAndDetectChanges(value, ref _isLockedOut, Ps.Value.IsLockedOutSelector); } + get => _isLockedOut; + set => SetPropertyValueAndDetectChanges(value, ref _isLockedOut, nameof(IsLockedOut)); } [IgnoreDataMember] public DateTime LastLoginDate { - get { return _lastLoginDate; } - set { SetPropertyValueAndDetectChanges(value, ref _lastLoginDate, Ps.Value.LastLoginDateSelector); } + get => _lastLoginDate; + set => SetPropertyValueAndDetectChanges(value, ref _lastLoginDate, nameof(LastLoginDate)); } [IgnoreDataMember] public DateTime LastPasswordChangeDate { - get { return _lastPasswordChangedDate; } - set { SetPropertyValueAndDetectChanges(value, ref _lastPasswordChangedDate, Ps.Value.LastPasswordChangeDateSelector); } + get => _lastPasswordChangedDate; + set => SetPropertyValueAndDetectChanges(value, ref _lastPasswordChangedDate, nameof(LastPasswordChangeDate)); } [IgnoreDataMember] public DateTime LastLockoutDate { - get { return _lastLockoutDate; } - set { SetPropertyValueAndDetectChanges(value, ref _lastLockoutDate, Ps.Value.LastLockoutDateSelector); } + get => _lastLockoutDate; + set => SetPropertyValueAndDetectChanges(value, ref _lastLockoutDate, nameof(LastLockoutDate)); } [IgnoreDataMember] public int FailedPasswordAttempts { - get { return _failedLoginAttempts; } - set { SetPropertyValueAndDetectChanges(value, ref _failedLoginAttempts, Ps.Value.FailedPasswordAttemptsSelector); } + get => _failedLoginAttempts; + set => SetPropertyValueAndDetectChanges(value, ref _failedLoginAttempts, nameof(FailedPasswordAttempts)); } // TODO: Figure out how to support all of this! - we cannot have NotImplementedExceptions because these get used by the IMembershipMemberService service so @@ -279,8 +242,8 @@ namespace Umbraco.Core.Models.Membership [DataMember] public string Name { - get { return _name; } - set { SetPropertyValueAndDetectChanges(value, ref _name, Ps.Value.NameSelector); } + get => _name; + set => SetPropertyValueAndDetectChanges(value, ref _name, nameof(Name)); } public IEnumerable AllowedSections @@ -295,10 +258,7 @@ namespace Umbraco.Core.Models.Membership [IgnoreDataMember] internal List GroupsToSave = new List(); - public IProfile ProfileData - { - get { return new WrappedUserProfile(this); } - } + public IProfile ProfileData => new WrappedUserProfile(this); /// /// The security stamp used by ASP.Net identity @@ -306,15 +266,15 @@ namespace Umbraco.Core.Models.Membership [IgnoreDataMember] public string SecurityStamp { - get { return _securityStamp; } - set { SetPropertyValueAndDetectChanges(value, ref _securityStamp, Ps.Value.SecurityStampSelector); } + get => _securityStamp; + set => SetPropertyValueAndDetectChanges(value, ref _securityStamp, nameof(SecurityStamp)); } [DataMember] public string Avatar { - get { return _avatar; } - set { SetPropertyValueAndDetectChanges(value, ref _avatar, Ps.Value.AvatarSelector); } + get => _avatar; + set => SetPropertyValueAndDetectChanges(value, ref _avatar, nameof(Avatar)); } /// @@ -323,8 +283,8 @@ namespace Umbraco.Core.Models.Membership [DataMember] public string TourData { - get { return _tourData; } - set { SetPropertyValueAndDetectChanges(value, ref _tourData, Ps.Value.TourDataSelector); } + get => _tourData; + set => SetPropertyValueAndDetectChanges(value, ref _tourData, nameof(TourData)); } /// @@ -336,8 +296,8 @@ namespace Umbraco.Core.Models.Membership [DataMember] public int SessionTimeout { - get { return _sessionTimeout; } - set { SetPropertyValueAndDetectChanges(value, ref _sessionTimeout, Ps.Value.SessionTimeoutSelector); } + get => _sessionTimeout; + set => SetPropertyValueAndDetectChanges(value, ref _sessionTimeout, nameof(SessionTimeout)); } /// @@ -350,8 +310,8 @@ namespace Umbraco.Core.Models.Membership [DoNotClone] public int[] StartContentIds { - get { return _startContentIds; } - set { SetPropertyValueAndDetectChanges(value, ref _startContentIds, Ps.Value.StartContentIdSelector, Ps.Value.IntegerEnumerableComparer); } + get => _startContentIds; + set => SetPropertyValueAndDetectChanges(value, ref _startContentIds, nameof(StartContentIds), IntegerEnumerableComparer); } /// @@ -364,32 +324,29 @@ namespace Umbraco.Core.Models.Membership [DoNotClone] public int[] StartMediaIds { - get { return _startMediaIds; } - set { SetPropertyValueAndDetectChanges(value, ref _startMediaIds, Ps.Value.StartMediaIdSelector, Ps.Value.IntegerEnumerableComparer); } + get => _startMediaIds; + set => SetPropertyValueAndDetectChanges(value, ref _startMediaIds, nameof(StartMediaIds), IntegerEnumerableComparer); } [DataMember] public string Language { - get { return _language; } - set { SetPropertyValueAndDetectChanges(value, ref _language, Ps.Value.LanguageSelector); } + get => _language; + set => SetPropertyValueAndDetectChanges(value, ref _language, nameof(Language)); } [IgnoreDataMember] internal bool DefaultToLiveEditing { - get { return _defaultToLiveEditing; } - set { SetPropertyValueAndDetectChanges(value, ref _defaultToLiveEditing, Ps.Value.DefaultToLiveEditingSelector); } + get => _defaultToLiveEditing; + set => SetPropertyValueAndDetectChanges(value, ref _defaultToLiveEditing, nameof(DefaultToLiveEditing)); } /// /// Gets the groups that user is part of /// [DataMember] - public IEnumerable Groups - { - get { return _userGroups; } - } + public IEnumerable Groups => _userGroups; public void RemoveGroup(string group) { @@ -400,7 +357,7 @@ namespace Umbraco.Core.Models.Membership _userGroups.Remove(userGroup); //reset this flag so it's rebuilt with the assigned groups _allowedSections = null; - OnPropertyChanged(Ps.Value.UserGroupsSelector); + OnPropertyChanged(nameof(Groups)); } } } @@ -412,7 +369,7 @@ namespace Umbraco.Core.Models.Membership _userGroups.Clear(); //reset this flag so it's rebuilt with the assigned groups _allowedSections = null; - OnPropertyChanged(Ps.Value.UserGroupsSelector); + OnPropertyChanged(nameof(Groups)); } } @@ -422,7 +379,7 @@ namespace Umbraco.Core.Models.Membership { //reset this flag so it's rebuilt with the assigned groups _allowedSections = null; - OnPropertyChanged(Ps.Value.UserGroupsSelector); + OnPropertyChanged(nameof(Groups)); } } @@ -446,7 +403,7 @@ namespace Umbraco.Core.Models.Membership [IgnoreDataMember] [DoNotClone] - internal object AdditionalDataLock { get { return _additionalDataLock; } } + internal object AdditionalDataLock => _additionalDataLock; protected override void PerformDeepClone(object clone) { @@ -498,15 +455,9 @@ namespace Umbraco.Core.Models.Membership _user = user; } - public int Id - { - get { return _user.Id; } - } + public int Id => _user.Id; - public string Name - { - get { return _user.Name; } - } + public string Name => _user.Name; private bool Equals(WrappedUserProfile other) { diff --git a/src/Umbraco.Core/Models/Membership/UserGroup.cs b/src/Umbraco.Core/Models/Membership/UserGroup.cs index e3e812f4c1..31421f990d 100644 --- a/src/Umbraco.Core/Models/Membership/UserGroup.cs +++ b/src/Umbraco.Core/Models/Membership/UserGroup.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Models.Entities; using Umbraco.Core.Strings; @@ -22,24 +21,11 @@ namespace Umbraco.Core.Models.Membership private IEnumerable _permissions; private readonly List _sectionCollection; - private static readonly Lazy Ps = new Lazy(); - - // ReSharper disable once ClassNeverInstantiated.Local // lazy-instantiated in Ps - private class PropertySelectors - { - public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo(x => x.Name); - public readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo(x => x.Alias); - public readonly PropertyInfo PermissionsSelector = ExpressionHelper.GetPropertyInfo>(x => x.Permissions); - public readonly PropertyInfo IconSelector = ExpressionHelper.GetPropertyInfo(x => x.Icon); - public readonly PropertyInfo StartContentIdSelector = ExpressionHelper.GetPropertyInfo(x => x.StartContentId); - public readonly PropertyInfo StartMediaIdSelector = ExpressionHelper.GetPropertyInfo(x => x.StartMediaId); - - //Custom comparer for enumerable - public readonly DelegateEqualityComparer> StringEnumerableComparer = - new DelegateEqualityComparer>( - (enum1, enum2) => enum1.UnsortedSequenceEqual(enum2), - enum1 => enum1.GetHashCode()); - } + //Custom comparer for enumerable + private static readonly DelegateEqualityComparer> StringEnumerableComparer = + new DelegateEqualityComparer>( + (enum1, enum2) => enum1.UnsortedSequenceEqual(enum2), + enum1 => enum1.GetHashCode()); /// /// Constructor to create a new user group @@ -71,35 +57,35 @@ namespace Umbraco.Core.Models.Membership public int? StartMediaId { get => _startMediaId; - set => SetPropertyValueAndDetectChanges(value, ref _startMediaId, Ps.Value.StartMediaIdSelector); + set => SetPropertyValueAndDetectChanges(value, ref _startMediaId, nameof(StartMediaId)); } [DataMember] public int? StartContentId { get => _startContentId; - set => SetPropertyValueAndDetectChanges(value, ref _startContentId, Ps.Value.StartContentIdSelector); + set => SetPropertyValueAndDetectChanges(value, ref _startContentId, nameof(StartContentId)); } [DataMember] public string Icon { get => _icon; - set => SetPropertyValueAndDetectChanges(value, ref _icon, Ps.Value.IconSelector); + set => SetPropertyValueAndDetectChanges(value, ref _icon, nameof(Icon)); } [DataMember] public string Alias { get => _alias; - set => SetPropertyValueAndDetectChanges(value.ToCleanString(CleanStringType.Alias | CleanStringType.UmbracoCase), ref _alias, Ps.Value.AliasSelector); + set => SetPropertyValueAndDetectChanges(value.ToCleanString(CleanStringType.Alias | CleanStringType.UmbracoCase), ref _alias, nameof(Alias)); } [DataMember] public string Name { get => _name; - set => SetPropertyValueAndDetectChanges(value, ref _name, Ps.Value.NameSelector); + set => SetPropertyValueAndDetectChanges(value, ref _name, nameof(Name)); } /// @@ -112,7 +98,7 @@ namespace Umbraco.Core.Models.Membership public IEnumerable Permissions { get => _permissions; - set => SetPropertyValueAndDetectChanges(value, ref _permissions, Ps.Value.PermissionsSelector, Ps.Value.StringEnumerableComparer); + set => SetPropertyValueAndDetectChanges(value, ref _permissions, nameof(Permissions), StringEnumerableComparer); } public IEnumerable AllowedSections => _sectionCollection; diff --git a/src/Umbraco.Core/Models/MigrationEntry.cs b/src/Umbraco.Core/Models/MigrationEntry.cs index 9ac9ae58a4..1af66d2978 100644 --- a/src/Umbraco.Core/Models/MigrationEntry.cs +++ b/src/Umbraco.Core/Models/MigrationEntry.cs @@ -1,5 +1,4 @@ using System; -using System.Reflection; using Semver; using Umbraco.Core.Models.Entities; @@ -19,27 +18,19 @@ namespace Umbraco.Core.Models _version = version; } - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo(x => x.MigrationName); - public readonly PropertyInfo VersionSelector = ExpressionHelper.GetPropertyInfo(x => x.Version); - } - private string _migrationName; private SemVersion _version; public string MigrationName { - get { return _migrationName; } - set { SetPropertyValueAndDetectChanges(value, ref _migrationName, Ps.Value.NameSelector); } + get => _migrationName; + set => SetPropertyValueAndDetectChanges(value, ref _migrationName, nameof(MigrationName)); } public SemVersion Version { - get { return _version; } - set { SetPropertyValueAndDetectChanges(value, ref _version, Ps.Value.VersionSelector); } + get => _version; + set => SetPropertyValueAndDetectChanges(value, ref _version, nameof(Version)); } } } diff --git a/src/Umbraco.Core/Models/Property.cs b/src/Umbraco.Core/Models/Property.cs index 11b5239a70..726ddc1cf5 100644 --- a/src/Umbraco.Core/Models/Property.cs +++ b/src/Umbraco.Core/Models/Property.cs @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Collections; using Umbraco.Core.Models.Entities; @@ -25,8 +24,6 @@ namespace Umbraco.Core.Models // _vvalues contains the (indexed) variant property values private Dictionary _vvalues; - private static readonly Lazy Ps = new Lazy(); - /// /// Initializes a new instance of the class. /// @@ -100,32 +97,25 @@ namespace Umbraco.Core.Models => new PropertyValue { _culture = _culture, _segment = _segment, PublishedValue = PublishedValue, EditedValue = EditedValue }; } - // ReSharper disable once ClassNeverInstantiated.Local - private class PropertySelectors - { - // TODO: This allows us to track changes for an entire Property, but doesn't allow us to track changes at the variant level - public readonly PropertyInfo ValuesSelector = ExpressionHelper.GetPropertyInfo(x => x.Values); + private static readonly DelegateEqualityComparer PropertyValueComparer = new DelegateEqualityComparer( + (o, o1) => + { + if (o == null && o1 == null) return true; - public readonly DelegateEqualityComparer PropertyValueComparer = new DelegateEqualityComparer( - (o, o1) => - { - if (o == null && o1 == null) return true; + // custom comparer for strings. + // if one is null and another is empty then they are the same + if (o is string || o1 is string) + return ((o as string).IsNullOrWhiteSpace() && (o1 as string).IsNullOrWhiteSpace()) || (o != null && o1 != null && o.Equals(o1)); - // custom comparer for strings. - // if one is null and another is empty then they are the same - if (o is string || o1 is string) - return ((o as string).IsNullOrWhiteSpace() && (o1 as string).IsNullOrWhiteSpace()) || (o != null && o1 != null && o.Equals(o1)); + if (o == null || o1 == null) return false; - if (o == null || o1 == null) return false; + // custom comparer for enumerable + // ReSharper disable once MergeCastWithTypeCheck + if (o is IEnumerable && o1 is IEnumerable enumerable) + return ((IEnumerable)o).Cast().UnsortedSequenceEqual(enumerable.Cast()); - // custom comparer for enumerable - // ReSharper disable once MergeCastWithTypeCheck - if (o is IEnumerable && o1 is IEnumerable enumerable) - return ((IEnumerable) o).Cast().UnsortedSequenceEqual(enumerable.Cast()); - - return o.Equals(o1); - }, o => o.GetHashCode()); - } + return o.Equals(o1); + }, o => o.GetHashCode()); /// /// Returns the PropertyType, which this Property is based on @@ -258,7 +248,7 @@ namespace Umbraco.Core.Models throw new NotSupportedException("Property type does not support publishing."); var origValue = pvalue.PublishedValue; pvalue.PublishedValue = PropertyType.ConvertAssignedValue(pvalue.EditedValue); - DetectChanges(pvalue.EditedValue, origValue, Ps.Value.ValuesSelector, Ps.Value.PropertyValueComparer, false); + DetectChanges(pvalue.EditedValue, origValue, nameof(Values), PropertyValueComparer, false); } private void UnpublishValue(PropertyValue pvalue) @@ -269,7 +259,7 @@ namespace Umbraco.Core.Models throw new NotSupportedException("Property type does not support publishing."); var origValue = pvalue.PublishedValue; pvalue.PublishedValue = PropertyType.ConvertAssignedValue(null); - DetectChanges(pvalue.EditedValue, origValue, Ps.Value.ValuesSelector, Ps.Value.PropertyValueComparer, false); + DetectChanges(pvalue.EditedValue, origValue, nameof(Values), PropertyValueComparer, false); } /// @@ -290,7 +280,7 @@ namespace Umbraco.Core.Models pvalue.EditedValue = setValue; - DetectChanges(setValue, origValue, Ps.Value.ValuesSelector, Ps.Value.PropertyValueComparer, change); + DetectChanges(setValue, origValue, nameof(Values), PropertyValueComparer, change); } // bypasses all changes detection and is the *only* way to set the published value diff --git a/src/Umbraco.Core/Models/PropertyGroup.cs b/src/Umbraco.Core/Models/PropertyGroup.cs index 595e8d1d6a..2e6da5d837 100644 --- a/src/Umbraco.Core/Models/PropertyGroup.cs +++ b/src/Umbraco.Core/Models/PropertyGroup.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Specialized; using System.Diagnostics; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Models.Entities; @@ -15,8 +14,6 @@ namespace Umbraco.Core.Models [DebuggerDisplay("Id: {Id}, Name: {Name}")] public class PropertyGroup : EntityBase, IEquatable { - private static readonly Lazy Ps = new Lazy(); - private string _name; private int _sortOrder; private PropertyTypeCollection _propertyTypes; @@ -30,17 +27,9 @@ namespace Umbraco.Core.Models PropertyTypes = propertyTypeCollection; } - // ReSharper disable once ClassNeverInstantiated.Local - private class PropertySelectors - { - public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo(x => x.Name); - public readonly PropertyInfo SortOrderSelector = ExpressionHelper.GetPropertyInfo(x => x.SortOrder); - public readonly PropertyInfo PropertyTypes = ExpressionHelper.GetPropertyInfo(x => x.PropertyTypes); - } - private void PropertyTypesChanged(object sender, NotifyCollectionChangedEventArgs e) { - OnPropertyChanged(Ps.Value.PropertyTypes); + OnPropertyChanged(nameof(PropertyTypes)); } /// @@ -50,7 +39,7 @@ namespace Umbraco.Core.Models public string Name { get => _name; - set => SetPropertyValueAndDetectChanges(value, ref _name, Ps.Value.NameSelector); + set => SetPropertyValueAndDetectChanges(value, ref _name, nameof(Name)); } /// @@ -60,7 +49,7 @@ namespace Umbraco.Core.Models public int SortOrder { get => _sortOrder; - set => SetPropertyValueAndDetectChanges(value, ref _sortOrder, Ps.Value.SortOrderSelector); + set => SetPropertyValueAndDetectChanges(value, ref _sortOrder, nameof(SortOrder)); } /// @@ -85,7 +74,7 @@ namespace Umbraco.Core.Models foreach (var propertyType in _propertyTypes) propertyType.PropertyGroupId = new Lazy(() => Id); - OnPropertyChanged(Ps.Value.PropertyTypes); + OnPropertyChanged(nameof(PropertyTypes)); _propertyTypes.CollectionChanged += PropertyTypesChanged; } } diff --git a/src/Umbraco.Core/Models/PropertyType.cs b/src/Umbraco.Core/Models/PropertyType.cs index 107831ebdd..1d6a3b4fe9 100644 --- a/src/Umbraco.Core/Models/PropertyType.cs +++ b/src/Umbraco.Core/Models/PropertyType.cs @@ -1,11 +1,7 @@ using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; using System.Diagnostics; using System.Linq; -using System.Reflection; using System.Runtime.Serialization; -using System.Text.RegularExpressions; using Umbraco.Core.Composing; using Umbraco.Core.Models.Entities; using Umbraco.Core.Strings; @@ -20,8 +16,6 @@ namespace Umbraco.Core.Models [DebuggerDisplay("Id: {Id}, Name: {Name}, Alias: {Alias}")] public class PropertyType : EntityBase, IEquatable { - private static PropertySelectors _selectors; - private readonly bool _forceValueStorageType; private string _name; private string _alias; @@ -87,23 +81,6 @@ namespace Umbraco.Core.Models _variations = ContentVariation.Nothing; } - private static PropertySelectors Selectors => _selectors ?? (_selectors = new PropertySelectors()); - - private class PropertySelectors - { - public readonly PropertyInfo Name = ExpressionHelper.GetPropertyInfo(x => x.Name); - public readonly PropertyInfo Alias = ExpressionHelper.GetPropertyInfo(x => x.Alias); - public readonly PropertyInfo Description = ExpressionHelper.GetPropertyInfo(x => x.Description); - public readonly PropertyInfo DataTypeId = ExpressionHelper.GetPropertyInfo(x => x.DataTypeId); - public readonly PropertyInfo PropertyEditorAlias = ExpressionHelper.GetPropertyInfo(x => x.PropertyEditorAlias); - public readonly PropertyInfo ValueStorageType = ExpressionHelper.GetPropertyInfo(x => x.ValueStorageType); - public readonly PropertyInfo Mandatory = ExpressionHelper.GetPropertyInfo(x => x.Mandatory); - public readonly PropertyInfo SortOrder = ExpressionHelper.GetPropertyInfo(x => x.SortOrder); - public readonly PropertyInfo ValidationRegExp = ExpressionHelper.GetPropertyInfo(x => x.ValidationRegExp); - public readonly PropertyInfo PropertyGroupId = ExpressionHelper.GetPropertyInfo>(x => x.PropertyGroupId); - public readonly PropertyInfo VaryBy = ExpressionHelper.GetPropertyInfo(x => x.Variations); - } - /// /// Gets a value indicating whether the content type, owning this property type, is publishing. /// @@ -116,7 +93,7 @@ namespace Umbraco.Core.Models public string Name { get => _name; - set => SetPropertyValueAndDetectChanges(value, ref _name, Selectors.Name); + set => SetPropertyValueAndDetectChanges(value, ref _name, nameof(Name)); } /// @@ -126,7 +103,7 @@ namespace Umbraco.Core.Models public string Alias { get => _alias; - set => SetPropertyValueAndDetectChanges(SanitizeAlias(value), ref _alias, Selectors.Alias); + set => SetPropertyValueAndDetectChanges(SanitizeAlias(value), ref _alias, nameof(Alias)); } /// @@ -136,7 +113,7 @@ namespace Umbraco.Core.Models public string Description { get => _description; - set => SetPropertyValueAndDetectChanges(value, ref _description, Selectors.Description); + set => SetPropertyValueAndDetectChanges(value, ref _description, nameof(Description)); } /// @@ -146,7 +123,7 @@ namespace Umbraco.Core.Models public int DataTypeId { get => _dataTypeId; - set => SetPropertyValueAndDetectChanges(value, ref _dataTypeId, Selectors.DataTypeId); + set => SetPropertyValueAndDetectChanges(value, ref _dataTypeId, nameof(DataTypeId)); } /// @@ -156,7 +133,7 @@ namespace Umbraco.Core.Models public string PropertyEditorAlias { get => _propertyEditorAlias; - set => SetPropertyValueAndDetectChanges(value, ref _propertyEditorAlias, Selectors.PropertyEditorAlias); + set => SetPropertyValueAndDetectChanges(value, ref _propertyEditorAlias, nameof(PropertyEditorAlias)); } /// @@ -169,7 +146,7 @@ namespace Umbraco.Core.Models set { if (_forceValueStorageType) return; // ignore changes - SetPropertyValueAndDetectChanges(value, ref _valueStorageType, Selectors.ValueStorageType); + SetPropertyValueAndDetectChanges(value, ref _valueStorageType, nameof(ValueStorageType)); } } @@ -181,7 +158,7 @@ namespace Umbraco.Core.Models internal Lazy PropertyGroupId { get => _propertyGroupId; - set => SetPropertyValueAndDetectChanges(value, ref _propertyGroupId, Selectors.PropertyGroupId); + set => SetPropertyValueAndDetectChanges(value, ref _propertyGroupId, nameof(PropertyGroupId)); } /// @@ -191,7 +168,7 @@ namespace Umbraco.Core.Models public bool Mandatory { get => _mandatory; - set => SetPropertyValueAndDetectChanges(value, ref _mandatory, Selectors.Mandatory); + set => SetPropertyValueAndDetectChanges(value, ref _mandatory, nameof(Mandatory)); } /// @@ -201,7 +178,7 @@ namespace Umbraco.Core.Models public int SortOrder { get => _sortOrder; - set => SetPropertyValueAndDetectChanges(value, ref _sortOrder, Selectors.SortOrder); + set => SetPropertyValueAndDetectChanges(value, ref _sortOrder, nameof(SortOrder)); } /// @@ -211,7 +188,7 @@ namespace Umbraco.Core.Models public string ValidationRegExp { get => _validationRegExp; - set => SetPropertyValueAndDetectChanges(value, ref _validationRegExp, Selectors.ValidationRegExp); + set => SetPropertyValueAndDetectChanges(value, ref _validationRegExp, nameof(ValidationRegExp)); } /// @@ -220,7 +197,7 @@ namespace Umbraco.Core.Models public ContentVariation Variations { get => _variations; - set => SetPropertyValueAndDetectChanges(value, ref _variations, Selectors.VaryBy); + set => SetPropertyValueAndDetectChanges(value, ref _variations, nameof(Variations)); } /// diff --git a/src/Umbraco.Core/Models/PublicAccessEntry.cs b/src/Umbraco.Core/Models/PublicAccessEntry.cs index df2d9f9ddc..cfb30de147 100644 --- a/src/Umbraco.Core/Models/PublicAccessEntry.cs +++ b/src/Umbraco.Core/Models/PublicAccessEntry.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Linq; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Models.Entities; @@ -54,7 +53,7 @@ namespace Umbraco.Core.Models void _ruleCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { - OnPropertyChanged(Ps.Value.AllowedSectionsSelector); + OnPropertyChanged(nameof(Rules)); //if (e.Action == NotifyCollectionChangedAction.Add) //{ @@ -77,26 +76,10 @@ namespace Umbraco.Core.Models } } + + internal IEnumerable RemovedRules => _removedRules; - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo ProtectedNodeIdSelector = ExpressionHelper.GetPropertyInfo(x => x.ProtectedNodeId); - public readonly PropertyInfo LoginNodeIdSelector = ExpressionHelper.GetPropertyInfo(x => x.LoginNodeId); - public readonly PropertyInfo NoAccessNodeIdSelector = ExpressionHelper.GetPropertyInfo(x => x.NoAccessNodeId); - public readonly PropertyInfo AllowedSectionsSelector = ExpressionHelper.GetPropertyInfo>(x => x.Rules); - } - - internal IEnumerable RemovedRules - { - get { return _removedRules; } - } - - public IEnumerable Rules - { - get { return _ruleCollection; } - } + public IEnumerable Rules => _ruleCollection; public PublicAccessRule AddRule(string ruleValue, string ruleType) { @@ -129,22 +112,22 @@ namespace Umbraco.Core.Models [DataMember] public int LoginNodeId { - get { return _loginNodeId; } - set { SetPropertyValueAndDetectChanges(value, ref _loginNodeId, Ps.Value.LoginNodeIdSelector); } + get => _loginNodeId; + set => SetPropertyValueAndDetectChanges(value, ref _loginNodeId, nameof(LoginNodeId)); } [DataMember] public int NoAccessNodeId { - get { return _noAccessNodeId; } - set { SetPropertyValueAndDetectChanges(value, ref _noAccessNodeId, Ps.Value.NoAccessNodeIdSelector); } + get => _noAccessNodeId; + set => SetPropertyValueAndDetectChanges(value, ref _noAccessNodeId, nameof(NoAccessNodeId)); } [DataMember] public int ProtectedNodeId { - get { return _protectedNodeId; } - set { SetPropertyValueAndDetectChanges(value, ref _protectedNodeId, Ps.Value.ProtectedNodeIdSelector); } + get => _protectedNodeId; + set => SetPropertyValueAndDetectChanges(value, ref _protectedNodeId, nameof(ProtectedNodeId)); } public override void ResetDirtyProperties(bool rememberDirty) diff --git a/src/Umbraco.Core/Models/PublicAccessRule.cs b/src/Umbraco.Core/Models/PublicAccessRule.cs index 67b9ece2f9..bb6c1cdea2 100644 --- a/src/Umbraco.Core/Models/PublicAccessRule.cs +++ b/src/Umbraco.Core/Models/PublicAccessRule.cs @@ -1,5 +1,4 @@ using System; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Models.Entities; @@ -23,26 +22,18 @@ namespace Umbraco.Core.Models { } - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo RuleValueSelector = ExpressionHelper.GetPropertyInfo(x => x.RuleValue); - public readonly PropertyInfo RuleTypeSelector = ExpressionHelper.GetPropertyInfo(x => x.RuleType); - } - public Guid AccessEntryId { get; internal set; } public string RuleValue { - get { return _ruleValue; } - set { SetPropertyValueAndDetectChanges(value, ref _ruleValue, Ps.Value.RuleValueSelector); } + get => _ruleValue; + set => SetPropertyValueAndDetectChanges(value, ref _ruleValue, nameof(RuleValue)); } public string RuleType { - get { return _ruleType; } - set { SetPropertyValueAndDetectChanges(value, ref _ruleType, Ps.Value.RuleTypeSelector); } + get => _ruleType; + set => SetPropertyValueAndDetectChanges(value, ref _ruleType, nameof(RuleType)); } diff --git a/src/Umbraco.Core/Models/RedirectUrl.cs b/src/Umbraco.Core/Models/RedirectUrl.cs index 55b799244e..f4eb955c64 100644 --- a/src/Umbraco.Core/Models/RedirectUrl.cs +++ b/src/Umbraco.Core/Models/RedirectUrl.cs @@ -1,5 +1,4 @@ using System; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Models.Entities; @@ -20,18 +19,6 @@ namespace Umbraco.Core.Models CreateDateUtc = DateTime.UtcNow; } - private static readonly Lazy Ps = new Lazy(); - - // ReSharper disable once ClassNeverInstantiated.Local - private class PropertySelectors - { - public readonly PropertyInfo ContentIdSelector = ExpressionHelper.GetPropertyInfo(x => x.ContentId); - public readonly PropertyInfo ContentKeySelector = ExpressionHelper.GetPropertyInfo(x => x.ContentKey); - public readonly PropertyInfo CreateDateUtcSelector = ExpressionHelper.GetPropertyInfo(x => x.CreateDateUtc); - public readonly PropertyInfo CultureSelector = ExpressionHelper.GetPropertyInfo(x => x.Culture); - public readonly PropertyInfo UrlSelector = ExpressionHelper.GetPropertyInfo(x => x.Url); - } - private int _contentId; private Guid _contentKey; private DateTime _createDateUtc; @@ -41,36 +28,36 @@ namespace Umbraco.Core.Models /// public int ContentId { - get { return _contentId; } - set { SetPropertyValueAndDetectChanges(value, ref _contentId, Ps.Value.ContentIdSelector); } + get => _contentId; + set => SetPropertyValueAndDetectChanges(value, ref _contentId, nameof(ContentId)); } /// public Guid ContentKey { - get { return _contentKey; } - set { SetPropertyValueAndDetectChanges(value, ref _contentKey, Ps.Value.ContentKeySelector); } + get => _contentKey; + set => SetPropertyValueAndDetectChanges(value, ref _contentKey, nameof(ContentKey)); } /// public DateTime CreateDateUtc { - get { return _createDateUtc; } - set { SetPropertyValueAndDetectChanges(value, ref _createDateUtc, Ps.Value.CreateDateUtcSelector); } + get => _createDateUtc; + set => SetPropertyValueAndDetectChanges(value, ref _createDateUtc, nameof(CreateDateUtc)); } /// public string Culture { - get { return _culture; } - set { SetPropertyValueAndDetectChanges(value, ref _culture, Ps.Value.CultureSelector); } + get => _culture; + set => SetPropertyValueAndDetectChanges(value, ref _culture, nameof(Culture)); } /// public string Url { - get { return _url; } - set { SetPropertyValueAndDetectChanges(value, ref _url, Ps.Value.UrlSelector); } + get => _url; + set => SetPropertyValueAndDetectChanges(value, ref _url, nameof(Url)); } } } diff --git a/src/Umbraco.Core/Models/Relation.cs b/src/Umbraco.Core/Models/Relation.cs index 2d2b05dbd6..f5d13c70c4 100644 --- a/src/Umbraco.Core/Models/Relation.cs +++ b/src/Umbraco.Core/Models/Relation.cs @@ -1,8 +1,6 @@ using System; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Models.Entities; -using Umbraco.Core.Persistence.Mappers; namespace Umbraco.Core.Models { @@ -25,16 +23,7 @@ namespace Umbraco.Core.Models _childId = childId; _relationType = relationType; } - - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo ParentIdSelector = ExpressionHelper.GetPropertyInfo(x => x.ParentId); - public readonly PropertyInfo ChildIdSelector = ExpressionHelper.GetPropertyInfo(x => x.ChildId); - public readonly PropertyInfo RelationTypeSelector = ExpressionHelper.GetPropertyInfo(x => x.RelationType); - public readonly PropertyInfo CommentSelector = ExpressionHelper.GetPropertyInfo(x => x.Comment); - } + /// /// Gets or sets the Parent Id of the Relation (Source) @@ -42,8 +31,8 @@ namespace Umbraco.Core.Models [DataMember] public int ParentId { - get { return _parentId; } - set { SetPropertyValueAndDetectChanges(value, ref _parentId, Ps.Value.ParentIdSelector); } + get => _parentId; + set => SetPropertyValueAndDetectChanges(value, ref _parentId, nameof(ParentId)); } /// @@ -52,8 +41,8 @@ namespace Umbraco.Core.Models [DataMember] public int ChildId { - get { return _childId; } - set { SetPropertyValueAndDetectChanges(value, ref _childId, Ps.Value.ChildIdSelector); } + get => _childId; + set => SetPropertyValueAndDetectChanges(value, ref _childId, nameof(ChildId)); } /// @@ -62,8 +51,8 @@ namespace Umbraco.Core.Models [DataMember] public IRelationType RelationType { - get { return _relationType; } - set { SetPropertyValueAndDetectChanges(value, ref _relationType, Ps.Value.RelationTypeSelector); } + get => _relationType; + set => SetPropertyValueAndDetectChanges(value, ref _relationType, nameof(RelationType)); } /// @@ -72,18 +61,14 @@ namespace Umbraco.Core.Models [DataMember] public string Comment { - get { return _comment; } - set { SetPropertyValueAndDetectChanges(value, ref _comment, Ps.Value.CommentSelector); } + get => _comment; + set => SetPropertyValueAndDetectChanges(value, ref _comment, nameof(Comment)); } /// /// Gets the Id of the that this Relation is based on. /// [IgnoreDataMember] - public int RelationTypeId - { - get { return _relationType.Id; } - } - + public int RelationTypeId => _relationType.Id; } } diff --git a/src/Umbraco.Core/Models/RelationType.cs b/src/Umbraco.Core/Models/RelationType.cs index 5aa2c19ce3..259b7bc4ef 100644 --- a/src/Umbraco.Core/Models/RelationType.cs +++ b/src/Umbraco.Core/Models/RelationType.cs @@ -1,9 +1,7 @@ using System; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Exceptions; using Umbraco.Core.Models.Entities; -using Umbraco.Core.Persistence.Mappers; namespace Umbraco.Core.Models { @@ -36,25 +34,14 @@ namespace Umbraco.Core.Models Name = name; } - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo(x => x.Name); - public readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo(x => x.Alias); - public readonly PropertyInfo IsBidirectionalSelector = ExpressionHelper.GetPropertyInfo(x => x.IsBidirectional); - public readonly PropertyInfo ParentObjectTypeSelector = ExpressionHelper.GetPropertyInfo(x => x.ParentObjectType); - public readonly PropertyInfo ChildObjectTypeSelector = ExpressionHelper.GetPropertyInfo(x => x.ChildObjectType); - } - /// /// Gets or sets the Name of the RelationType /// [DataMember] public string Name { - get { return _name; } - set { SetPropertyValueAndDetectChanges(value, ref _name, Ps.Value.NameSelector); } + get => _name; + set => SetPropertyValueAndDetectChanges(value, ref _name, nameof(Name)); } /// @@ -63,8 +50,8 @@ namespace Umbraco.Core.Models [DataMember] public string Alias { - get { return _alias; } - set { SetPropertyValueAndDetectChanges(value, ref _alias, Ps.Value.AliasSelector); } + get => _alias; + set => SetPropertyValueAndDetectChanges(value, ref _alias, nameof(Alias)); } /// @@ -73,8 +60,8 @@ namespace Umbraco.Core.Models [DataMember] public bool IsBidirectional { - get { return _isBidrectional; } - set { SetPropertyValueAndDetectChanges(value, ref _isBidrectional, Ps.Value.IsBidirectionalSelector); } + get => _isBidrectional; + set => SetPropertyValueAndDetectChanges(value, ref _isBidrectional, nameof(IsBidirectional)); } /// @@ -84,8 +71,8 @@ namespace Umbraco.Core.Models [DataMember] public Guid ParentObjectType { - get { return _parentObjectType; } - set { SetPropertyValueAndDetectChanges(value, ref _parentObjectType, Ps.Value.ParentObjectTypeSelector); } + get => _parentObjectType; + set => SetPropertyValueAndDetectChanges(value, ref _parentObjectType, nameof(ParentObjectType)); } /// @@ -95,8 +82,8 @@ namespace Umbraco.Core.Models [DataMember] public Guid ChildObjectType { - get { return _childObjectType; } - set { SetPropertyValueAndDetectChanges(value, ref _childObjectType, Ps.Value.ChildObjectTypeSelector); } + get => _childObjectType; + set => SetPropertyValueAndDetectChanges(value, ref _childObjectType, nameof(ChildObjectType)); } } diff --git a/src/Umbraco.Core/Models/ServerRegistration.cs b/src/Umbraco.Core/Models/ServerRegistration.cs index db0e9b8c3b..7dae5d5393 100644 --- a/src/Umbraco.Core/Models/ServerRegistration.cs +++ b/src/Umbraco.Core/Models/ServerRegistration.cs @@ -1,6 +1,5 @@ using System; using System.Globalization; -using System.Reflection; using Umbraco.Core.Models.Entities; namespace Umbraco.Core.Models @@ -15,16 +14,6 @@ namespace Umbraco.Core.Models private bool _isActive; private bool _isMaster; - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo ServerAddressSelector = ExpressionHelper.GetPropertyInfo(x => x.ServerAddress); - public readonly PropertyInfo ServerIdentitySelector = ExpressionHelper.GetPropertyInfo(x => x.ServerIdentity); - public readonly PropertyInfo IsActiveSelector = ExpressionHelper.GetPropertyInfo(x => x.IsActive); - public readonly PropertyInfo IsMasterSelector = ExpressionHelper.GetPropertyInfo(x => x.IsMaster); - } - /// /// Initializes a new instance of the class. /// @@ -73,8 +62,8 @@ namespace Umbraco.Core.Models /// public string ServerAddress { - get { return _serverAddress; } - set { SetPropertyValueAndDetectChanges(value, ref _serverAddress, Ps.Value.ServerAddressSelector); } + get => _serverAddress; + set => SetPropertyValueAndDetectChanges(value, ref _serverAddress, nameof(ServerAddress)); } /// @@ -82,8 +71,8 @@ namespace Umbraco.Core.Models /// public string ServerIdentity { - get { return _serverIdentity; } - set { SetPropertyValueAndDetectChanges(value, ref _serverIdentity, Ps.Value.ServerIdentitySelector); } + get => _serverIdentity; + set => SetPropertyValueAndDetectChanges(value, ref _serverIdentity, nameof(ServerIdentity)); } /// @@ -91,8 +80,8 @@ namespace Umbraco.Core.Models /// public bool IsActive { - get { return _isActive; } - set { SetPropertyValueAndDetectChanges(value, ref _isActive, Ps.Value.IsActiveSelector); } + get => _isActive; + set => SetPropertyValueAndDetectChanges(value, ref _isActive, nameof(IsActive)); } /// @@ -100,19 +89,27 @@ namespace Umbraco.Core.Models /// public bool IsMaster { - get { return _isMaster; } - set { SetPropertyValueAndDetectChanges(value, ref _isMaster, Ps.Value.IsMasterSelector); } + get => _isMaster; + set => SetPropertyValueAndDetectChanges(value, ref _isMaster, nameof(IsMaster)); } /// /// Gets the date and time the registration was created. /// - public DateTime Registered { get { return CreateDate; } set { CreateDate = value; }} + public DateTime Registered + { + get => CreateDate; + set => CreateDate = value; + } /// /// Gets the date and time the registration was last accessed. /// - public DateTime Accessed { get { return UpdateDate; } set { UpdateDate = value; }} + public DateTime Accessed + { + get => UpdateDate; + set => UpdateDate = value; + } /// /// Converts the value of this instance to its equivalent string representation. diff --git a/src/Umbraco.Core/Models/StylesheetProperty.cs b/src/Umbraco.Core/Models/StylesheetProperty.cs index 1601ca3e76..089f89deb6 100644 --- a/src/Umbraco.Core/Models/StylesheetProperty.cs +++ b/src/Umbraco.Core/Models/StylesheetProperty.cs @@ -1,5 +1,4 @@ using System; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Models.Entities; @@ -25,14 +24,6 @@ namespace Umbraco.Core.Models _value = value; } - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo(x => x.Alias); - public readonly PropertyInfo ValueSelector = ExpressionHelper.GetPropertyInfo(x => x.Value); - } - /// /// The CSS rule name that can be used by Umbraco in the back office /// @@ -43,8 +34,8 @@ namespace Umbraco.Core.Models /// public string Alias { - get { return _alias; } - set { SetPropertyValueAndDetectChanges(value, ref _alias, Ps.Value.AliasSelector); } + get => _alias; + set => SetPropertyValueAndDetectChanges(value, ref _alias, nameof(Alias)); } /// @@ -52,8 +43,8 @@ namespace Umbraco.Core.Models /// public string Value { - get { return _value; } - set { SetPropertyValueAndDetectChanges(value, ref _value, Ps.Value.ValueSelector); } + get => _value; + set => SetPropertyValueAndDetectChanges(value, ref _value, nameof(Value)); } } diff --git a/src/Umbraco.Core/Models/Tag.cs b/src/Umbraco.Core/Models/Tag.cs index e9707e587d..315904493e 100644 --- a/src/Umbraco.Core/Models/Tag.cs +++ b/src/Umbraco.Core/Models/Tag.cs @@ -1,5 +1,4 @@ using System; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Models.Entities; @@ -12,8 +11,6 @@ namespace Umbraco.Core.Models [DataContract(IsReference = true)] public class Tag : EntityBase, ITag { - private static PropertySelectors _selectors; - private string _group; private string _text; private int? _languageId; @@ -35,34 +32,25 @@ namespace Umbraco.Core.Models LanguageId = languageId; } - private static PropertySelectors Selectors => _selectors ?? (_selectors = new PropertySelectors()); - - private class PropertySelectors - { - public readonly PropertyInfo Group = ExpressionHelper.GetPropertyInfo(x => x.Group); - public readonly PropertyInfo Text = ExpressionHelper.GetPropertyInfo(x => x.Text); - public readonly PropertyInfo LanguageId = ExpressionHelper.GetPropertyInfo(x => x.LanguageId); - } - /// public string Group { get => _group; - set => SetPropertyValueAndDetectChanges(value, ref _group, Selectors.Group); + set => SetPropertyValueAndDetectChanges(value, ref _group, nameof(Group)); } /// public string Text { get => _text; - set => SetPropertyValueAndDetectChanges(value, ref _text, Selectors.Text); + set => SetPropertyValueAndDetectChanges(value, ref _text, nameof(Text)); } /// public int? LanguageId { get => _languageId; - set => SetPropertyValueAndDetectChanges(value, ref _languageId, Selectors.LanguageId); + set => SetPropertyValueAndDetectChanges(value, ref _languageId, nameof(LanguageId)); } /// diff --git a/src/Umbraco.Core/Models/Template.cs b/src/Umbraco.Core/Models/Template.cs index b7e67c45ea..db473972e3 100644 --- a/src/Umbraco.Core/Models/Template.cs +++ b/src/Umbraco.Core/Models/Template.cs @@ -1,5 +1,4 @@ using System; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Strings; @@ -17,16 +16,6 @@ namespace Umbraco.Core.Models private string _masterTemplateAlias; private Lazy _masterTemplateId; - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo MasterTemplateAliasSelector = ExpressionHelper.GetPropertyInfo(x => x.MasterTemplateAlias); - public readonly PropertyInfo MasterTemplateIdSelector = ExpressionHelper.GetPropertyInfo>(x => x.MasterTemplateId); - public readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo(x => x.Alias); - public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo(x => x.Name); - } - public Template(string name, string alias) : this(name, alias, (Func) null) { } @@ -42,28 +31,28 @@ namespace Umbraco.Core.Models [DataMember] public Lazy MasterTemplateId { - get { return _masterTemplateId; } - set { SetPropertyValueAndDetectChanges(value, ref _masterTemplateId, Ps.Value.MasterTemplateIdSelector); } + get => _masterTemplateId; + set => SetPropertyValueAndDetectChanges(value, ref _masterTemplateId, nameof(MasterTemplateId)); } public string MasterTemplateAlias { - get { return _masterTemplateAlias; } - set { SetPropertyValueAndDetectChanges(value, ref _masterTemplateAlias, Ps.Value.MasterTemplateAliasSelector); } + get => _masterTemplateAlias; + set => SetPropertyValueAndDetectChanges(value, ref _masterTemplateAlias, nameof(MasterTemplateAlias)); } [DataMember] public new string Name { - get { return _name; } - set { SetPropertyValueAndDetectChanges(value, ref _name, Ps.Value.NameSelector); } + get => _name; + set => SetPropertyValueAndDetectChanges(value, ref _name, nameof(Name)); } [DataMember] public new string Alias { - get { return _alias; } - set { SetPropertyValueAndDetectChanges(value.ToCleanString(CleanStringType.UnderscoreAlias), ref _alias, Ps.Value.AliasSelector); } + get => _alias; + set => SetPropertyValueAndDetectChanges(value.ToCleanString(CleanStringType.UnderscoreAlias), ref _alias, nameof(Alias)); } /// diff --git a/src/Umbraco.Core/Models/UmbracoDomain.cs b/src/Umbraco.Core/Models/UmbracoDomain.cs index d7266f77fe..093acef5b5 100644 --- a/src/Umbraco.Core/Models/UmbracoDomain.cs +++ b/src/Umbraco.Core/Models/UmbracoDomain.cs @@ -1,5 +1,4 @@ using System; -using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Models.Entities; @@ -24,40 +23,28 @@ namespace Umbraco.Core.Models private int? _languageId; private string _domainName; - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo ContentSelector = ExpressionHelper.GetPropertyInfo(x => x.RootContentId); - public readonly PropertyInfo DefaultLanguageSelector = ExpressionHelper.GetPropertyInfo(x => x.LanguageId); - public readonly PropertyInfo DomainNameSelector = ExpressionHelper.GetPropertyInfo(x => x.DomainName); - } - [DataMember] public int? LanguageId { - get { return _languageId; } - set { SetPropertyValueAndDetectChanges(value, ref _languageId, Ps.Value.DefaultLanguageSelector); } + get => _languageId; + set => SetPropertyValueAndDetectChanges(value, ref _languageId, nameof(LanguageId)); } [DataMember] public string DomainName { - get { return _domainName; } - set { SetPropertyValueAndDetectChanges(value, ref _domainName, Ps.Value.DomainNameSelector); } + get => _domainName; + set => SetPropertyValueAndDetectChanges(value, ref _domainName, nameof(DomainName)); } [DataMember] public int? RootContentId { - get { return _contentId; } - set { SetPropertyValueAndDetectChanges(value, ref _contentId, Ps.Value.ContentSelector); } + get => _contentId; + set => SetPropertyValueAndDetectChanges(value, ref _contentId, nameof(RootContentId)); } - public bool IsWildcard - { - get { return string.IsNullOrWhiteSpace(DomainName) || DomainName.StartsWith("*"); } - } + public bool IsWildcard => string.IsNullOrWhiteSpace(DomainName) || DomainName.StartsWith("*"); /// /// Readonly value of the language ISO code for the domain diff --git a/src/Umbraco.Tests/Cache/DeepCloneAppCacheTests.cs b/src/Umbraco.Tests/Cache/DeepCloneAppCacheTests.cs index 11e2c56873..13fabe5ca2 100644 --- a/src/Umbraco.Tests/Cache/DeepCloneAppCacheTests.cs +++ b/src/Umbraco.Tests/Cache/DeepCloneAppCacheTests.cs @@ -17,10 +17,7 @@ namespace Umbraco.Tests.Cache { private DeepCloneAppCache _provider; - protected override int GetTotalItemCount - { - get { return HttpRuntime.Cache.Count; } - } + protected override int GetTotalItemCount => HttpRuntime.Cache.Count; public override void Setup() { @@ -28,15 +25,9 @@ namespace Umbraco.Tests.Cache _provider = new DeepCloneAppCache(new WebCachingAppCache(HttpRuntime.Cache)); } - internal override IAppCache AppCache - { - get { return _provider; } - } + internal override IAppCache AppCache => _provider; - internal override IAppPolicyCache AppPolicyCache - { - get { return _provider; } - } + internal override IAppPolicyCache AppPolicyCache => _provider; [Test] public void Clones_List() @@ -101,18 +92,11 @@ namespace Umbraco.Tests.Cache CloneId = Guid.NewGuid(); } - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo WriterSelector = ExpressionHelper.GetPropertyInfo(x => x.Name); - } - private string _name; public string Name { - get { return _name; } - set { SetPropertyValueAndDetectChanges(value, ref _name, Ps.Value.WriterSelector); } + get => _name; + set => SetPropertyValueAndDetectChanges(value, ref _name, nameof(Name)); } public Guid CloneId { get; set; }