Merge branch 'temp8-fixes-allocations-for-property-selectors' into temp8

This commit is contained in:
Stephan
2019-02-04 10:09:43 +01:00
40 changed files with 368 additions and 915 deletions
+11 -27
View File
@@ -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<AuditEntry, int>(x => x.PerformingUserId);
public readonly PropertyInfo PerformingDetails = ExpressionHelper.GetPropertyInfo<AuditEntry, string>(x => x.PerformingDetails);
public readonly PropertyInfo PerformingIp = ExpressionHelper.GetPropertyInfo<AuditEntry, string>(x => x.PerformingIp);
public readonly PropertyInfo AffectedUserId = ExpressionHelper.GetPropertyInfo<AuditEntry, int>(x => x.AffectedUserId);
public readonly PropertyInfo AffectedDetails = ExpressionHelper.GetPropertyInfo<AuditEntry, string>(x => x.AffectedDetails);
public readonly PropertyInfo EventType = ExpressionHelper.GetPropertyInfo<AuditEntry, string>(x => x.EventType);
public readonly PropertyInfo EventDetails = ExpressionHelper.GetPropertyInfo<AuditEntry, string>(x => x.EventDetails);
}
/// <inheritdoc />
public int PerformingUserId
{
get => _performingUserId;
set => SetPropertyValueAndDetectChanges(value, ref _performingUserId, Selectors.PerformingUserId);
set => SetPropertyValueAndDetectChanges(value, ref _performingUserId, nameof(PerformingUserId));
}
/// <inheritdoc />
public string PerformingDetails
{
get => _performingDetails;
set => SetPropertyValueAndDetectChanges(value, ref _performingDetails, Selectors.PerformingDetails);
set => SetPropertyValueAndDetectChanges(value, ref _performingDetails, nameof(PerformingDetails));
}
/// <inheritdoc />
public string PerformingIp
{
get => _performingIp;
set => SetPropertyValueAndDetectChanges(value, ref _performingIp, Selectors.PerformingIp);
set => SetPropertyValueAndDetectChanges(value, ref _performingIp, nameof(PerformingIp));
}
/// <inheritdoc />
@@ -64,31 +48,31 @@ namespace Umbraco.Core.Models
}
/// <inheritdoc />
public int AffectedUserId
public int AffectedUserId
{
get => _affectedUserId;
set => SetPropertyValueAndDetectChanges(value, ref _affectedUserId, Selectors.AffectedUserId);
set => SetPropertyValueAndDetectChanges(value, ref _affectedUserId, nameof(AffectedUserId));
}
/// <inheritdoc />
public string AffectedDetails
public string AffectedDetails
{
get => _affectedDetails;
set => SetPropertyValueAndDetectChanges(value, ref _affectedDetails, Selectors.AffectedDetails);
set => SetPropertyValueAndDetectChanges(value, ref _affectedDetails, nameof(AffectedDetails));
}
/// <inheritdoc />
public string EventType
public string EventType
{
get => _eventType;
set => SetPropertyValueAndDetectChanges(value, ref _eventType, Selectors.EventType);
set => SetPropertyValueAndDetectChanges(value, ref _eventType, nameof(EventType));
}
/// <inheritdoc />
public string EventDetails
public string EventDetails
{
get => _eventDetails;
set => SetPropertyValueAndDetectChanges(value, ref _eventDetails, Selectors.EventDetails);
set => SetPropertyValueAndDetectChanges(value, ref _eventDetails, nameof(EventDetails));
}
}
}
+6 -22
View File
@@ -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<Consent, bool>(x => x.Current);
public readonly PropertyInfo Source = ExpressionHelper.GetPropertyInfo<Consent, string>(x => x.Source);
public readonly PropertyInfo Context = ExpressionHelper.GetPropertyInfo<Consent, string>(x => x.Context);
public readonly PropertyInfo Action = ExpressionHelper.GetPropertyInfo<Consent, string>(x => x.Action);
public readonly PropertyInfo State = ExpressionHelper.GetPropertyInfo<Consent, ConsentState>(x => x.State);
public readonly PropertyInfo Comment = ExpressionHelper.GetPropertyInfo<Consent, string>(x => x.Comment);
}
private static PropertySelectors Selectors => _selector ?? (_selector = new PropertySelectors());
/// <inheritdoc />
public bool Current
{
get => _current;
set => SetPropertyValueAndDetectChanges(value, ref _current, Selectors.Current);
set => SetPropertyValueAndDetectChanges(value, ref _current, nameof(Current));
}
/// <inheritdoc />
@@ -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));
}
/// <inheritdoc />
public string Comment
{
get => _comment;
set => SetPropertyValueAndDetectChanges(value, ref _comment, Selectors.Comment);
set => SetPropertyValueAndDetectChanges(value, ref _comment, nameof(Comment));
}
/// <inheritdoc />
+5 -17
View File
@@ -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<string> _editedCultures;
private static readonly Lazy<PropertySelectors> Ps = new Lazy<PropertySelectors>();
/// <summary>
/// Constructor for creating a Content object
/// </summary>
@@ -81,15 +78,6 @@ namespace Umbraco.Core.Models
PublishedVersionId = 0;
}
// ReSharper disable once ClassNeverInstantiated.Local
private class PropertySelectors
{
public readonly PropertyInfo TemplateSelector = ExpressionHelper.GetPropertyInfo<Content, int?>(x => x.TemplateId);
public readonly PropertyInfo PublishedSelector = ExpressionHelper.GetPropertyInfo<Content, bool>(x => x.Published);
public readonly PropertyInfo ContentScheduleSelector = ExpressionHelper.GetPropertyInfo<Content, ContentScheduleCollection>(x => x.ContentSchedule);
public readonly PropertyInfo PublishCultureInfosSelector = ExpressionHelper.GetPropertyInfo<Content, IReadOnlyDictionary<string, ContentCultureInfos>>(x => x.PublishCultureInfos);
}
/// <inheritdoc />
[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
/// <param name="e"></param>
private void ScheduleCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
OnPropertyChanged(Ps.Value.ContentScheduleSelector);
OnPropertyChanged(nameof(ContentSchedule));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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
/// </summary>
private void PublishNamesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
OnPropertyChanged(Ps.Value.PublishCultureInfosSelector);
OnPropertyChanged(nameof(PublishCultureInfos));
}
[IgnoreDataMember]
+4 -15
View File
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
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<ContentBase, int>(x => x.ContentTypeId);
public readonly PropertyInfo PropertyCollectionSelector = ExpressionHelper.GetPropertyInfo<ContentBase, PropertyCollection>(x => x.Properties);
public readonly PropertyInfo WriterSelector = ExpressionHelper.GetPropertyInfo<ContentBase, int>(x => x.WriterId);
public readonly PropertyInfo CultureInfosSelector = ExpressionHelper.GetPropertyInfo<ContentBase, IReadOnlyDictionary<string, ContentCultureInfos>>(x => x.CultureInfos);
}
protected void PropertiesChanged(object sender, NotifyCollectionChangedEventArgs e)
{
OnPropertyChanged(Ps.Value.PropertyCollectionSelector);
OnPropertyChanged(nameof(Properties));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -251,7 +240,7 @@ namespace Umbraco.Core.Models
/// </summary>
private void CultureInfosCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
OnPropertyChanged(Ps.Value.CultureInfosSelector);
OnPropertyChanged(nameof(CultureInfos));
}
#endregion
+2 -11
View File
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
/// <summary>
/// Initializes a new instance of the <see cref="ContentCultureInfos"/> 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));
}
/// <summary>
@@ -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));
}
/// <inheritdoc />
@@ -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<ContentCultureInfos, string>(x => x.Name);
public readonly PropertyInfo DateSelector = ExpressionHelper.GetPropertyInfo<ContentCultureInfos, DateTime>(x => x.Date);
}
}
}
+7 -15
View File
@@ -13,7 +13,6 @@ namespace Umbraco.Core.Models
[DataContract(IsReference = true)]
public class ContentType : ContentTypeCompositionBase, IContentType
{
private static readonly Lazy<PropertySelectors> Ps = new Lazy<PropertySelectors>();
public const bool IsPublishingConst = true;
private int _defaultTemplate;
@@ -45,17 +44,10 @@ namespace Umbraco.Core.Models
/// <inheritdoc />
public override bool IsPublishing => IsPublishingConst;
// ReSharper disable once ClassNeverInstantiated.Local
private class PropertySelectors
{
public readonly PropertyInfo DefaultTemplateSelector = ExpressionHelper.GetPropertyInfo<ContentType, int>(x => x.DefaultTemplateId);
public readonly PropertyInfo AllowedTemplatesSelector = ExpressionHelper.GetPropertyInfo<ContentType, IEnumerable<ITemplate>>(x => x.AllowedTemplates);
//Custom comparer for enumerable
public readonly DelegateEqualityComparer<IEnumerable<ITemplate>> TemplateComparer = new DelegateEqualityComparer<IEnumerable<ITemplate>>(
(templates, enumerable) => templates.UnsortedSequenceEqual(enumerable),
templates => templates.GetHashCode());
}
//Custom comparer for enumerable
private static readonly DelegateEqualityComparer<IEnumerable<ITemplate>> TemplateComparer = new DelegateEqualityComparer<IEnumerable<ITemplate>>(
(templates, enumerable) => templates.UnsortedSequenceEqual(enumerable),
templates => templates.GetHashCode());
/// <summary>
/// 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));
}
/// <summary>
@@ -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;
+21 -41
View File
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private string _alias;
private string _description;
private string _icon = "icon-folder";
@@ -83,37 +80,20 @@ namespace Umbraco.Core.Models
/// </remarks>
public abstract bool IsPublishing { get; }
// ReSharper disable once ClassNeverInstantiated.Local
private class PropertySelectors
{
public readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo<ContentTypeBase, string>(x => x.Alias);
public readonly PropertyInfo DescriptionSelector = ExpressionHelper.GetPropertyInfo<ContentTypeBase, string>(x => x.Description);
public readonly PropertyInfo IconSelector = ExpressionHelper.GetPropertyInfo<ContentTypeBase, string>(x => x.Icon);
public readonly PropertyInfo ThumbnailSelector = ExpressionHelper.GetPropertyInfo<ContentTypeBase, string>(x => x.Thumbnail);
public readonly PropertyInfo AllowedAsRootSelector = ExpressionHelper.GetPropertyInfo<ContentTypeBase, bool>(x => x.AllowedAsRoot);
public readonly PropertyInfo IsElementSelector = ExpressionHelper.GetPropertyInfo<ContentTypeBase, bool>(x => x.IsElement);
public readonly PropertyInfo IsContainerSelector = ExpressionHelper.GetPropertyInfo<ContentTypeBase, bool>(x => x.IsContainer);
public readonly PropertyInfo AllowedContentTypesSelector = ExpressionHelper.GetPropertyInfo<ContentTypeBase, IEnumerable<ContentTypeSort>>(x => x.AllowedContentTypes);
public readonly PropertyInfo PropertyGroupsSelector = ExpressionHelper.GetPropertyInfo<ContentTypeBase, PropertyGroupCollection>(x => x.PropertyGroups);
public readonly PropertyInfo PropertyTypesSelector = ExpressionHelper.GetPropertyInfo<ContentTypeBase, IEnumerable<PropertyType>>(x => x.PropertyTypes);
public readonly PropertyInfo HasPropertyTypeBeenRemovedSelector = ExpressionHelper.GetPropertyInfo<ContentTypeBase, bool>(x => x.HasPropertyTypeBeenRemoved);
public readonly PropertyInfo VaryBy = ExpressionHelper.GetPropertyInfo<ContentTypeBase, ContentVariation>(x => x.Variations);
//Custom comparer for enumerable
public readonly DelegateEqualityComparer<IEnumerable<ContentTypeSort>> ContentTypeSortComparer =
new DelegateEqualityComparer<IEnumerable<ContentTypeSort>>(
(sorts, enumerable) => sorts.UnsortedSequenceEqual(enumerable),
sorts => sorts.GetHashCode());
}
//Custom comparer for enumerable
private static readonly DelegateEqualityComparer<IEnumerable<ContentTypeSort>> ContentTypeSortComparer =
new DelegateEqualityComparer<IEnumerable<ContentTypeSort>>(
(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));
}
/// <summary>
@@ -126,7 +106,7 @@ namespace Umbraco.Core.Models
set => SetPropertyValueAndDetectChanges(
value.ToCleanString(CleanStringType.Alias | CleanStringType.UmbracoCase),
ref _alias,
Ps.Value.AliasSelector);
nameof(Alias));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <inheritdoc />
@@ -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));
}
/// <summary>
@@ -197,8 +177,8 @@ namespace Umbraco.Core.Models
public IEnumerable<ContentTypeSort> AllowedContentTypes
{
get => _allowedContentTypes;
set => SetPropertyValueAndDetectChanges(value, ref _allowedContentTypes, Ps.Value.AllowedContentTypesSelector,
Ps.Value.ContentTypeSortComparer);
set => SetPropertyValueAndDetectChanges(value, ref _allowedContentTypes, nameof(AllowedContentTypes),
ContentTypeSortComparer);
}
/// <summary>
@@ -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));
}
/// <inheritdoc />
@@ -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));
}
/// <summary>
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private List<IContentTypeComposition> _contentTypeComposition = new List<IContentTypeComposition>();
internal List<int> RemovedContentTypeKeyTracker = new List<int>();
@@ -32,13 +29,6 @@ namespace Umbraco.Core.Models
AddContentType(parent);
}
// ReSharper disable once ClassNeverInstantiated.Local
private class PropertySelectors
{
public readonly PropertyInfo ContentTypeCompositionSelector =
ExpressionHelper.GetPropertyInfo<ContentTypeCompositionBase, IEnumerable<IContentTypeComposition>>(x => x.ContentTypeComposition);
}
/// <summary>
/// Gets or sets the content types that compose this content type.
/// </summary>
@@ -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;
+3 -15
View File
@@ -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<DataType, IDataEditor>(x => x.Editor);
public readonly PropertyInfo DatabaseType = ExpressionHelper.GetPropertyInfo<DataType, ValueStorageType>(x => x.DatabaseType);
public readonly PropertyInfo Configuration = ExpressionHelper.GetPropertyInfo<DataType, object>(x => x.Configuration);
}
/// <inheritdoc />
[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));
}
/// <inheritdoc />
@@ -124,7 +112,7 @@ namespace Umbraco.Core.Models
_configurationJson = null;
// it's always a change
OnPropertyChanged(Selectors.Configuration);
OnPropertyChanged(nameof(Configuration));
}
}
+9 -19
View File
@@ -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<IDictionaryTranslation>();
}
private static readonly Lazy<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private class PropertySelectors
{
public readonly PropertyInfo ParentIdSelector = ExpressionHelper.GetPropertyInfo<DictionaryItem, Guid?>(x => x.ParentId);
public readonly PropertyInfo ItemKeySelector = ExpressionHelper.GetPropertyInfo<DictionaryItem, string>(x => x.ItemKey);
public readonly PropertyInfo TranslationsSelector = ExpressionHelper.GetPropertyInfo<DictionaryItem, IEnumerable<IDictionaryTranslation>>(x => x.Translations);
//Custom comparer for enumerable
public readonly DelegateEqualityComparer<IEnumerable<IDictionaryTranslation>> DictionaryTranslationComparer =
new DelegateEqualityComparer<IEnumerable<IDictionaryTranslation>>(
(enumerable, translations) => enumerable.UnsortedSequenceEqual(translations),
enumerable => enumerable.GetHashCode());
}
//Custom comparer for enumerable
private static readonly DelegateEqualityComparer<IEnumerable<IDictionaryTranslation>> DictionaryTranslationComparer =
new DelegateEqualityComparer<IEnumerable<IDictionaryTranslation>>(
(enumerable, translations) => enumerable.UnsortedSequenceEqual(translations),
enumerable => enumerable.GetHashCode());
/// <summary>
/// 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)); }
}
/// <summary>
@@ -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)); }
}
/// <summary>
@@ -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);
}
}
}
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private class PropertySelectors
{
public readonly PropertyInfo LanguageSelector = ExpressionHelper.GetPropertyInfo<DictionaryTranslation, ILanguage>(x => x.Language);
public readonly PropertyInfo ValueSelector = ExpressionHelper.GetPropertyInfo<DictionaryTranslation, string>(x => x.Value);
}
/// <summary>
/// Gets or sets the <see cref="Language"/> for the translation
/// </summary>
@@ -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)
@@ -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
/// <typeparam name="T">The type of the value.</typeparam>
/// <param name="value">The new value.</param>
/// <param name="valueRef">A reference to the value to set.</param>
/// <param name="propertySelector">The property selector.</param>
/// <param name="propertyName">The property name.</param>
/// <param name="comparer">A comparer to compare property values.</param>
public new void SetPropertyValueAndDetectChanges<T>(T value, ref T valueRef, PropertyInfo propertySelector, IEqualityComparer<T> comparer = null)
public new void SetPropertyValueAndDetectChanges<T>(T value, ref T valueRef, string propertyName, IEqualityComparer<T> comparer = null)
{
base.SetPropertyValueAndDetectChanges(value, ref valueRef, propertySelector, comparer);
base.SetPropertyValueAndDetectChanges(value, ref valueRef, propertyName, comparer);
}
/// <summary>
/// Registers that a property has changed.
/// </summary>
public new void OnPropertyChanged(PropertyInfo propertySelector)
public new void OnPropertyChanged(string propertyName)
{
base.OnPropertyChanged(propertySelector);
base.OnPropertyChanged(propertyName);
}
}
}
@@ -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
/// <summary>
/// Registers that a property has changed.
/// </summary>
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<string, bool>();
_currentChanges[propertyInfo.Name] = true;
_currentChanges[propertyName] = true;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyInfo.Name));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
/// <summary>
@@ -143,9 +142,9 @@ namespace Umbraco.Core.Models.Entities
/// <typeparam name="T">The type of the value.</typeparam>
/// <param name="value">The new value.</param>
/// <param name="valueRef">A reference to the value to set.</param>
/// <param name="propertySelector">The property selector.</param>
/// <param name="propertyName">The property name.</param>
/// <param name="comparer">A comparer to compare property values.</param>
protected void SetPropertyValueAndDetectChanges<T>(T value, ref T valueRef, PropertyInfo propertySelector, IEqualityComparer<T> comparer = null)
protected void SetPropertyValueAndDetectChanges<T>(T value, ref T valueRef, string propertyName, IEqualityComparer<T> comparer = null)
{
if (comparer == null)
{
@@ -165,7 +164,7 @@ namespace Umbraco.Core.Models.Entities
// handle change
if (changed)
OnPropertyChanged(propertySelector);
OnPropertyChanged(propertyName);
}
/// <summary>
@@ -174,17 +173,17 @@ namespace Umbraco.Core.Models.Entities
/// <typeparam name="T">The type of the value.</typeparam>
/// <param name="value">The new value.</param>
/// <param name="orig">The original value.</param>
/// <param name="propertySelector">The property selector.</param>
/// <param name="propertyName">The property name.</param>
/// <param name="comparer">A comparer to compare property values.</param>
/// <param name="changed">A value indicating whether we know values have changed and no comparison is required.</param>
protected void DetectChanges<T>(T value, T orig, PropertyInfo propertySelector, IEqualityComparer<T> comparer, bool changed)
protected void DetectChanges<T>(T value, T orig, string propertyName, IEqualityComparer<T> comparer, bool changed)
{
// compare values
changed = _withChanges && (changed || !comparer.Equals(orig, value));
// handle change
if (changed)
OnPropertyChanged(propertySelector);
OnPropertyChanged(propertyName);
}
#endregion
+4 -16
View File
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
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<EntityBase, int>(x => x.Id);
public readonly PropertyInfo KeySelector = ExpressionHelper.GetPropertyInfo<EntityBase, Guid>(x => x.Key);
public readonly PropertyInfo CreateDateSelector = ExpressionHelper.GetPropertyInfo<EntityBase, DateTime>(x => x.CreateDate);
public readonly PropertyInfo UpdateDateSelector = ExpressionHelper.GetPropertyInfo<EntityBase, DateTime>(x => x.UpdateDate);
}
/// <inheritdoc />
[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));
}
/// <inheritdoc />
@@ -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));
}
/// <inheritdoc />
@@ -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));
}
/// <inheritdoc />
@@ -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
/// </summary>
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<ContentBase, string>(x => x.Name);
public readonly PropertyInfo CreatorId = ExpressionHelper.GetPropertyInfo<ContentBase, int>(x => x.CreatorId);
public readonly PropertyInfo ParentId = ExpressionHelper.GetPropertyInfo<ContentBase, int>(x => x.ParentId);
public readonly PropertyInfo Level = ExpressionHelper.GetPropertyInfo<ContentBase, int>(x => x.Level);
public readonly PropertyInfo Path = ExpressionHelper.GetPropertyInfo<ContentBase, string>(x => x.Path);
public readonly PropertyInfo SortOrder = ExpressionHelper.GetPropertyInfo<ContentBase, int>(x => x.SortOrder);
public readonly PropertyInfo Trashed = ExpressionHelper.GetPropertyInfo<ContentBase, bool>(x => x.Trashed);
}
/// <inheritdoc />
[DataMember]
public string Name
{
get => _name;
set => SetPropertyValueAndDetectChanges(value, ref _name, Selectors.Name);
set => SetPropertyValueAndDetectChanges(value, ref _name, nameof(Name));
}
/// <inheritdoc />
@@ -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));
}
/// <inheritdoc />
@@ -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));
}
/// <inheritdoc />
@@ -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));
}
/// <inheritdoc />
@@ -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));
}
/// <inheritdoc />
@@ -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));
}
/// <inheritdoc />
@@ -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));
}
}
}
+2 -14
View File
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private class PropertySelectors
{
public readonly PropertyInfo ContentSelector = ExpressionHelper.GetPropertyInfo<File, string>(x => x.Content);
public readonly PropertyInfo PathSelector = ExpressionHelper.GetPropertyInfo<File, string>(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));
}
}
@@ -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<int, IIdentityUserLogin, IdentityUserRole<string>, IdentityUserClaim<int>>, IRememberBeingDirty
{
private static readonly Lazy<PropertySelectors> Ps = new Lazy<PropertySelectors>();
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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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)); }
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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<IdentityUserRole<string>> _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<BackOfficeIdentityUser, string>(x => x.Email);
public readonly PropertyInfo UserNameSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, string>(x => x.UserName);
public readonly PropertyInfo LastLoginDateUtcSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, DateTime?>(x => x.LastLoginDateUtc);
public readonly PropertyInfo LastPasswordChangeDateUtcSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, DateTime?>(x => x.LastPasswordChangeDateUtc);
public readonly PropertyInfo EmailConfirmedSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, bool>(x => x.EmailConfirmed);
public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, string>(x => x.Name);
public readonly PropertyInfo AccessFailedCountSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, int>(x => x.AccessFailedCount);
public readonly PropertyInfo PasswordHashSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, string>(x => x.PasswordHash);
public readonly PropertyInfo CultureSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, string>(x => x.Culture);
public readonly PropertyInfo StartMediaIdsSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, int[]>(x => x.StartMediaIds);
public readonly PropertyInfo StartContentIdsSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, int[]>(x => x.StartContentIds);
public readonly PropertyInfo GroupsSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, IReadOnlyUserGroup[]>(x => x.Groups);
public readonly PropertyInfo LoginsSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, IEnumerable<IIdentityUserLogin>>(x => x.Logins);
public readonly PropertyInfo RolesSelector = ExpressionHelper.GetPropertyInfo<BackOfficeIdentityUser, IEnumerable<IdentityUserRole<string>>>(x => x.Roles);
//Custom comparer for enumerables
public readonly DelegateEqualityComparer<IReadOnlyUserGroup[]> GroupsComparer = new DelegateEqualityComparer<IReadOnlyUserGroup[]>(
(groups, enumerable) => groups.Select(x => x.Alias).UnsortedSequenceEqual(enumerable.Select(x => x.Alias)),
groups => groups.GetHashCode());
public readonly DelegateEqualityComparer<int[]> StartIdsComparer = new DelegateEqualityComparer<int[]>(
(groups, enumerable) => groups.UnsortedSequenceEqual(enumerable),
groups => groups.GetHashCode());
}
//Custom comparer for enumerables
private static readonly DelegateEqualityComparer<IReadOnlyUserGroup[]> GroupsComparer = new DelegateEqualityComparer<IReadOnlyUserGroup[]>(
(groups, enumerable) => groups.Select(x => x.Alias).UnsortedSequenceEqual(enumerable.Select(x => x.Alias)),
groups => groups.GetHashCode());
private static readonly DelegateEqualityComparer<int[]> StartIdsComparer = new DelegateEqualityComparer<int[]>(
(groups, enumerable) => groups.UnsortedSequenceEqual(enumerable),
groups => groups.GetHashCode());
}
}
+5 -19
View File
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
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<Language, string>(x => x.IsoCode);
public readonly PropertyInfo CultureNameSelector = ExpressionHelper.GetPropertyInfo<Language, string>(x => x.CultureName);
public readonly PropertyInfo IsDefaultVariantLanguageSelector = ExpressionHelper.GetPropertyInfo<Language, bool>(x => x.IsDefault);
public readonly PropertyInfo MandatorySelector = ExpressionHelper.GetPropertyInfo<Language, bool>(x => x.IsMandatory);
public readonly PropertyInfo FallbackLanguageSelector = ExpressionHelper.GetPropertyInfo<Language, int?>(x => x.FallbackLanguageId);
}
/// <inheritdoc />
[DataMember]
public string IsoCode
{
get => _isoCode;
set => SetPropertyValueAndDetectChanges(value, ref _isoCode, Ps.Value.IsoCodeSelector);
set => SetPropertyValueAndDetectChanges(value, ref _isoCode, nameof(IsoCode));
}
/// <inheritdoc />
@@ -102,7 +88,7 @@ namespace Umbraco.Core.Models
}
}
set => SetPropertyValueAndDetectChanges(value, ref _cultureName, Ps.Value.CultureNameSelector);
set => SetPropertyValueAndDetectChanges(value, ref _cultureName, nameof(CultureName));
}
/// <inheritdoc />
@@ -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));
}
/// <inheritdoc />
public bool IsMandatory
{
get => _mandatory;
set => SetPropertyValueAndDetectChanges(value, ref _mandatory, Ps.Value.MandatorySelector);
set => SetPropertyValueAndDetectChanges(value, ref _mandatory, nameof(IsMandatory));
}
/// <inheritdoc />
public int? FallbackLanguageId
{
get => _fallbackLanguageId;
set => SetPropertyValueAndDetectChanges(value, ref _fallbackLanguageId, Ps.Value.FallbackLanguageSelector);
set => SetPropertyValueAndDetectChanges(value, ref _fallbackLanguageId, nameof(FallbackLanguageId));
}
}
}
+23 -49
View File
@@ -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<string> _addedProperties;
private List<string> _removedProperties;
private static readonly Lazy<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private class PropertySelectors
{
public readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo<Macro, string>(x => x.Alias);
public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<Macro, string>(x => x.Name);
public readonly PropertyInfo UseInEditorSelector = ExpressionHelper.GetPropertyInfo<Macro, bool>(x => x.UseInEditor);
public readonly PropertyInfo CacheDurationSelector = ExpressionHelper.GetPropertyInfo<Macro, int>(x => x.CacheDuration);
public readonly PropertyInfo CacheByPageSelector = ExpressionHelper.GetPropertyInfo<Macro, bool>(x => x.CacheByPage);
public readonly PropertyInfo CacheByMemberSelector = ExpressionHelper.GetPropertyInfo<Macro, bool>(x => x.CacheByMember);
public readonly PropertyInfo DontRenderSelector = ExpressionHelper.GetPropertyInfo<Macro, bool>(x => x.DontRender);
public readonly PropertyInfo ScriptPathSelector = ExpressionHelper.GetPropertyInfo<Macro, string>(x => x.MacroSource);
public readonly PropertyInfo MacroTypeSelector = ExpressionHelper.GetPropertyInfo<Macro, MacroTypes>(x => x.MacroType);
public readonly PropertyInfo PropertiesSelector = ExpressionHelper.GetPropertyInfo<Macro, MacroPropertyCollection>(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
/// <param name="e"></param>
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
/// <summary>
/// Used internally to check if we need to add a section in the repository to the db
/// </summary>
internal IEnumerable<string> AddedProperties
{
get { return _addedProperties; }
}
internal IEnumerable<string> AddedProperties => _addedProperties;
/// <summary>
/// Used internally to check if we need to remove a section in the repository to the db
/// </summary>
internal IEnumerable<string> RemovedProperties
{
get { return _removedProperties; }
}
internal IEnumerable<string> RemovedProperties => _removedProperties;
/// <summary>
/// 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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
/// Gets or sets a list of Macro Properties
/// </summary>
[DataMember]
public MacroPropertyCollection Properties
{
get { return _properties; }
}
public MacroPropertyCollection Properties => _properties;
protected override void PerformDeepClone(object clone)
{
+13 -30
View File
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private class PropertySelectors
{
public readonly PropertyInfo KeySelector = ExpressionHelper.GetPropertyInfo<MacroProperty, Guid>(x => x.Key);
public readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo<MacroProperty, string>(x => x.Alias);
public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<MacroProperty, string>(x => x.Name);
public readonly PropertyInfo SortOrderSelector = ExpressionHelper.GetPropertyInfo<MacroProperty, int>(x => x.SortOrder);
public readonly PropertyInfo IdSelector = ExpressionHelper.GetPropertyInfo<EntityBase, int>(x => x.Id);
public readonly PropertyInfo PropertyTypeSelector = ExpressionHelper.GetPropertyInfo<MacroProperty, string>(x => x.EditorAlias);
}
/// <summary>
/// Gets or sets the Key of the Property
/// </summary>
[DataMember]
public Guid Key
{
get { return _key; }
set { SetPropertyValueAndDetectChanges(value, ref _key, Ps.Value.KeySelector); }
get => _key;
set => SetPropertyValueAndDetectChanges(value, ref _key, nameof(Key));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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()
+10 -33
View File
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private class PropertySelectors
{
public readonly PropertyInfo UsernameSelector = ExpressionHelper.GetPropertyInfo<Member, string>(x => x.Username);
public readonly PropertyInfo EmailSelector = ExpressionHelper.GetPropertyInfo<Member, string>(x => x.Email);
public readonly PropertyInfo PasswordSelector = ExpressionHelper.GetPropertyInfo<Member, string>(x => x.RawPasswordValue);
public readonly PropertyInfo ProviderUserKeySelector = ExpressionHelper.GetPropertyInfo<Member, object>(x => x.ProviderUserKey);
}
/// <summary>
/// Gets or sets the Username
/// </summary>
[DataMember]
public string Username
{
get { return _username; }
set { SetPropertyValueAndDetectChanges(value, ref _username, Ps.Value.UsernameSelector); }
get => _username;
set => SetPropertyValueAndDetectChanges(value, ref _username, nameof(Username));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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
/// </summary>
[DataMember]
public virtual string ContentTypeAlias
{
get { return _contentTypeAlias; }
}
public virtual string ContentTypeAlias => _contentTypeAlias;
/// <summary>
/// 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
/// </summary>
[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.
+2 -12
View File
@@ -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<string, object> _additionalData;
private string _name;
private int _creatorId;
private static PropertySelectors Selectors => _selectors ?? (_selectors = new PropertySelectors());
private class PropertySelectors
{
public readonly PropertyInfo Name = ExpressionHelper.GetPropertyInfo<MemberGroup, string>(x => x.Name);
public readonly PropertyInfo CreatorId = ExpressionHelper.GetPropertyInfo<MemberGroup, int>(x => x.CreatorId);
}
/// <inheritdoc />
[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));
}
}
}
+1 -9
View File
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
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<MemberType, string>(x => x.Alias);
}
/// <summary>
/// The Alias of the ContentType
/// </summary>
@@ -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));
}
}
+55 -104
View File
@@ -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<string, object> _additionalData;
private object _additionalDataLock = new object();
private static readonly Lazy<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private class PropertySelectors
{
public readonly PropertyInfo FailedPasswordAttemptsSelector = ExpressionHelper.GetPropertyInfo<User, int>(x => x.FailedPasswordAttempts);
public readonly PropertyInfo LastLockoutDateSelector = ExpressionHelper.GetPropertyInfo<User, DateTime>(x => x.LastLockoutDate);
public readonly PropertyInfo LastLoginDateSelector = ExpressionHelper.GetPropertyInfo<User, DateTime>(x => x.LastLoginDate);
public readonly PropertyInfo LastPasswordChangeDateSelector = ExpressionHelper.GetPropertyInfo<User, DateTime>(x => x.LastPasswordChangeDate);
public readonly PropertyInfo SecurityStampSelector = ExpressionHelper.GetPropertyInfo<User, string>(x => x.SecurityStamp);
public readonly PropertyInfo AvatarSelector = ExpressionHelper.GetPropertyInfo<User, string>(x => x.Avatar);
public readonly PropertyInfo TourDataSelector = ExpressionHelper.GetPropertyInfo<User, string>(x => x.TourData);
public readonly PropertyInfo SessionTimeoutSelector = ExpressionHelper.GetPropertyInfo<User, int>(x => x.SessionTimeout);
public readonly PropertyInfo StartContentIdSelector = ExpressionHelper.GetPropertyInfo<User, int[]>(x => x.StartContentIds);
public readonly PropertyInfo StartMediaIdSelector = ExpressionHelper.GetPropertyInfo<User, int[]>(x => x.StartMediaIds);
public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<User, string>(x => x.Name);
public readonly PropertyInfo UsernameSelector = ExpressionHelper.GetPropertyInfo<User, string>(x => x.Username);
public readonly PropertyInfo EmailSelector = ExpressionHelper.GetPropertyInfo<User, string>(x => x.Email);
public readonly PropertyInfo PasswordSelector = ExpressionHelper.GetPropertyInfo<User, string>(x => x.RawPasswordValue);
public readonly PropertyInfo IsLockedOutSelector = ExpressionHelper.GetPropertyInfo<User, bool>(x => x.IsLockedOut);
public readonly PropertyInfo IsApprovedSelector = ExpressionHelper.GetPropertyInfo<User, bool>(x => x.IsApproved);
public readonly PropertyInfo LanguageSelector = ExpressionHelper.GetPropertyInfo<User, string>(x => x.Language);
public readonly PropertyInfo EmailConfirmedDateSelector = ExpressionHelper.GetPropertyInfo<User, DateTime?>(x => x.EmailConfirmedDate);
public readonly PropertyInfo InvitedDateSelector = ExpressionHelper.GetPropertyInfo<User, DateTime?>(x => x.InvitedDate);
public readonly PropertyInfo DefaultToLiveEditingSelector = ExpressionHelper.GetPropertyInfo<User, bool>(x => x.DefaultToLiveEditing);
public readonly PropertyInfo UserGroupsSelector = ExpressionHelper.GetPropertyInfo<User, IEnumerable<IReadOnlyUserGroup>>(x => x.Groups);
//Custom comparer for enumerable
public readonly DelegateEqualityComparer<IEnumerable<int>> IntegerEnumerableComparer =
new DelegateEqualityComparer<IEnumerable<int>>(
(enum1, enum2) => enum1.UnsortedSequenceEqual(enum2),
enum1 => enum1.GetHashCode());
}
//Custom comparer for enumerable
private static readonly DelegateEqualityComparer<IEnumerable<int>> IntegerEnumerableComparer =
new DelegateEqualityComparer<IEnumerable<int>>(
(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<IUser> 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<string> AllowedSections
@@ -295,10 +258,7 @@ namespace Umbraco.Core.Models.Membership
[IgnoreDataMember]
internal List<IUserGroup> GroupsToSave = new List<IUserGroup>();
public IProfile ProfileData
{
get { return new WrappedUserProfile(this); }
}
public IProfile ProfileData => new WrappedUserProfile(this);
/// <summary>
/// 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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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);
}
/// <summary>
@@ -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));
}
/// <summary>
/// Gets the groups that user is part of
/// </summary>
[DataMember]
public IEnumerable<IReadOnlyUserGroup> Groups
{
get { return _userGroups; }
}
public IEnumerable<IReadOnlyUserGroup> 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)
{
+11 -25
View File
@@ -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<string> _permissions;
private readonly List<string> _sectionCollection;
private static readonly Lazy<PropertySelectors> Ps = new Lazy<PropertySelectors>();
// ReSharper disable once ClassNeverInstantiated.Local // lazy-instantiated in Ps
private class PropertySelectors
{
public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<UserGroup, string>(x => x.Name);
public readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo<UserGroup, string>(x => x.Alias);
public readonly PropertyInfo PermissionsSelector = ExpressionHelper.GetPropertyInfo<UserGroup, IEnumerable<string>>(x => x.Permissions);
public readonly PropertyInfo IconSelector = ExpressionHelper.GetPropertyInfo<UserGroup, string>(x => x.Icon);
public readonly PropertyInfo StartContentIdSelector = ExpressionHelper.GetPropertyInfo<UserGroup, int?>(x => x.StartContentId);
public readonly PropertyInfo StartMediaIdSelector = ExpressionHelper.GetPropertyInfo<UserGroup, int?>(x => x.StartMediaId);
//Custom comparer for enumerable
public readonly DelegateEqualityComparer<IEnumerable<string>> StringEnumerableComparer =
new DelegateEqualityComparer<IEnumerable<string>>(
(enum1, enum2) => enum1.UnsortedSequenceEqual(enum2),
enum1 => enum1.GetHashCode());
}
//Custom comparer for enumerable
private static readonly DelegateEqualityComparer<IEnumerable<string>> StringEnumerableComparer =
new DelegateEqualityComparer<IEnumerable<string>>(
(enum1, enum2) => enum1.UnsortedSequenceEqual(enum2),
enum1 => enum1.GetHashCode());
/// <summary>
/// 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));
}
/// <summary>
@@ -112,7 +98,7 @@ namespace Umbraco.Core.Models.Membership
public IEnumerable<string> Permissions
{
get => _permissions;
set => SetPropertyValueAndDetectChanges(value, ref _permissions, Ps.Value.PermissionsSelector, Ps.Value.StringEnumerableComparer);
set => SetPropertyValueAndDetectChanges(value, ref _permissions, nameof(Permissions), StringEnumerableComparer);
}
public IEnumerable<string> AllowedSections => _sectionCollection;
+4 -13
View File
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private class PropertySelectors
{
public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<MigrationEntry, string>(x => x.MigrationName);
public readonly PropertyInfo VersionSelector = ExpressionHelper.GetPropertyInfo<MigrationEntry, SemVersion>(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));
}
}
}
+18 -28
View File
@@ -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<CompositeNStringNStringKey, PropertyValue> _vvalues;
private static readonly Lazy<PropertySelectors> Ps = new Lazy<PropertySelectors>();
/// <summary>
/// Initializes a new instance of the <see cref="Property"/> class.
/// </summary>
@@ -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<Property, object>(x => x.Values);
private static readonly DelegateEqualityComparer<object> PropertyValueComparer = new DelegateEqualityComparer<object>(
(o, o1) =>
{
if (o == null && o1 == null) return true;
public readonly DelegateEqualityComparer<object> PropertyValueComparer = new DelegateEqualityComparer<object>(
(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<object>().UnsortedSequenceEqual(enumerable.Cast<object>());
// custom comparer for enumerable
// ReSharper disable once MergeCastWithTypeCheck
if (o is IEnumerable && o1 is IEnumerable enumerable)
return ((IEnumerable) o).Cast<object>().UnsortedSequenceEqual(enumerable.Cast<object>());
return o.Equals(o1);
}, o => o.GetHashCode());
}
return o.Equals(o1);
}, o => o.GetHashCode());
/// <summary>
/// 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);
}
/// <summary>
@@ -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
+4 -15
View File
@@ -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<PropertyGroup>
{
private static readonly Lazy<PropertySelectors> Ps = new Lazy<PropertySelectors>();
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<PropertyGroup, string>(x => x.Name);
public readonly PropertyInfo SortOrderSelector = ExpressionHelper.GetPropertyInfo<PropertyGroup, int>(x => x.SortOrder);
public readonly PropertyInfo PropertyTypes = ExpressionHelper.GetPropertyInfo<PropertyGroup, PropertyTypeCollection>(x => x.PropertyTypes);
}
private void PropertyTypesChanged(object sender, NotifyCollectionChangedEventArgs e)
{
OnPropertyChanged(Ps.Value.PropertyTypes);
OnPropertyChanged(nameof(PropertyTypes));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -85,7 +74,7 @@ namespace Umbraco.Core.Models
foreach (var propertyType in _propertyTypes)
propertyType.PropertyGroupId = new Lazy<int>(() => Id);
OnPropertyChanged(Ps.Value.PropertyTypes);
OnPropertyChanged(nameof(PropertyTypes));
_propertyTypes.CollectionChanged += PropertyTypesChanged;
}
}
+11 -34
View File
@@ -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<PropertyType>
{
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<PropertyType, string>(x => x.Name);
public readonly PropertyInfo Alias = ExpressionHelper.GetPropertyInfo<PropertyType, string>(x => x.Alias);
public readonly PropertyInfo Description = ExpressionHelper.GetPropertyInfo<PropertyType, string>(x => x.Description);
public readonly PropertyInfo DataTypeId = ExpressionHelper.GetPropertyInfo<PropertyType, int>(x => x.DataTypeId);
public readonly PropertyInfo PropertyEditorAlias = ExpressionHelper.GetPropertyInfo<PropertyType, string>(x => x.PropertyEditorAlias);
public readonly PropertyInfo ValueStorageType = ExpressionHelper.GetPropertyInfo<PropertyType, ValueStorageType>(x => x.ValueStorageType);
public readonly PropertyInfo Mandatory = ExpressionHelper.GetPropertyInfo<PropertyType, bool>(x => x.Mandatory);
public readonly PropertyInfo SortOrder = ExpressionHelper.GetPropertyInfo<PropertyType, int>(x => x.SortOrder);
public readonly PropertyInfo ValidationRegExp = ExpressionHelper.GetPropertyInfo<PropertyType, string>(x => x.ValidationRegExp);
public readonly PropertyInfo PropertyGroupId = ExpressionHelper.GetPropertyInfo<PropertyType, Lazy<int>>(x => x.PropertyGroupId);
public readonly PropertyInfo VaryBy = ExpressionHelper.GetPropertyInfo<PropertyType, ContentVariation>(x => x.Variations);
}
/// <summary>
/// Gets a value indicating whether the content type, owning this property type, is publishing.
/// </summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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<int> PropertyGroupId
{
get => _propertyGroupId;
set => SetPropertyValueAndDetectChanges(value, ref _propertyGroupId, Selectors.PropertyGroupId);
set => SetPropertyValueAndDetectChanges(value, ref _propertyGroupId, nameof(PropertyGroupId));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
+10 -27
View File
@@ -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<Guid> RemovedRules => _removedRules;
private static readonly Lazy<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private class PropertySelectors
{
public readonly PropertyInfo ProtectedNodeIdSelector = ExpressionHelper.GetPropertyInfo<PublicAccessEntry, int>(x => x.ProtectedNodeId);
public readonly PropertyInfo LoginNodeIdSelector = ExpressionHelper.GetPropertyInfo<PublicAccessEntry, int>(x => x.LoginNodeId);
public readonly PropertyInfo NoAccessNodeIdSelector = ExpressionHelper.GetPropertyInfo<PublicAccessEntry, int>(x => x.NoAccessNodeId);
public readonly PropertyInfo AllowedSectionsSelector = ExpressionHelper.GetPropertyInfo<PublicAccessEntry, IEnumerable<PublicAccessRule>>(x => x.Rules);
}
internal IEnumerable<Guid> RemovedRules
{
get { return _removedRules; }
}
public IEnumerable<PublicAccessRule> Rules
{
get { return _ruleCollection; }
}
public IEnumerable<PublicAccessRule> 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)
+4 -13
View File
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private class PropertySelectors
{
public readonly PropertyInfo RuleValueSelector = ExpressionHelper.GetPropertyInfo<PublicAccessRule, string>(x => x.RuleValue);
public readonly PropertyInfo RuleTypeSelector = ExpressionHelper.GetPropertyInfo<PublicAccessRule, string>(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));
}
+10 -23
View File
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
// ReSharper disable once ClassNeverInstantiated.Local
private class PropertySelectors
{
public readonly PropertyInfo ContentIdSelector = ExpressionHelper.GetPropertyInfo<RedirectUrl, int>(x => x.ContentId);
public readonly PropertyInfo ContentKeySelector = ExpressionHelper.GetPropertyInfo<RedirectUrl, Guid>(x => x.ContentKey);
public readonly PropertyInfo CreateDateUtcSelector = ExpressionHelper.GetPropertyInfo<RedirectUrl, DateTime>(x => x.CreateDateUtc);
public readonly PropertyInfo CultureSelector = ExpressionHelper.GetPropertyInfo<RedirectUrl, string>(x => x.Culture);
public readonly PropertyInfo UrlSelector = ExpressionHelper.GetPropertyInfo<RedirectUrl, string>(x => x.Url);
}
private int _contentId;
private Guid _contentKey;
private DateTime _createDateUtc;
@@ -41,36 +28,36 @@ namespace Umbraco.Core.Models
/// <inheritdoc />
public int ContentId
{
get { return _contentId; }
set { SetPropertyValueAndDetectChanges(value, ref _contentId, Ps.Value.ContentIdSelector); }
get => _contentId;
set => SetPropertyValueAndDetectChanges(value, ref _contentId, nameof(ContentId));
}
/// <inheritdoc />
public Guid ContentKey
{
get { return _contentKey; }
set { SetPropertyValueAndDetectChanges(value, ref _contentKey, Ps.Value.ContentKeySelector); }
get => _contentKey;
set => SetPropertyValueAndDetectChanges(value, ref _contentKey, nameof(ContentKey));
}
/// <inheritdoc />
public DateTime CreateDateUtc
{
get { return _createDateUtc; }
set { SetPropertyValueAndDetectChanges(value, ref _createDateUtc, Ps.Value.CreateDateUtcSelector); }
get => _createDateUtc;
set => SetPropertyValueAndDetectChanges(value, ref _createDateUtc, nameof(CreateDateUtc));
}
/// <inheritdoc />
public string Culture
{
get { return _culture; }
set { SetPropertyValueAndDetectChanges(value, ref _culture, Ps.Value.CultureSelector); }
get => _culture;
set => SetPropertyValueAndDetectChanges(value, ref _culture, nameof(Culture));
}
/// <inheritdoc />
public string Url
{
get { return _url; }
set { SetPropertyValueAndDetectChanges(value, ref _url, Ps.Value.UrlSelector); }
get => _url;
set => SetPropertyValueAndDetectChanges(value, ref _url, nameof(Url));
}
}
}
+10 -25
View File
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private class PropertySelectors
{
public readonly PropertyInfo ParentIdSelector = ExpressionHelper.GetPropertyInfo<Relation, int>(x => x.ParentId);
public readonly PropertyInfo ChildIdSelector = ExpressionHelper.GetPropertyInfo<Relation, int>(x => x.ChildId);
public readonly PropertyInfo RelationTypeSelector = ExpressionHelper.GetPropertyInfo<Relation, IRelationType>(x => x.RelationType);
public readonly PropertyInfo CommentSelector = ExpressionHelper.GetPropertyInfo<Relation, string>(x => x.Comment);
}
/// <summary>
/// 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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
/// Gets the Id of the <see cref="RelationType"/> that this Relation is based on.
/// </summary>
[IgnoreDataMember]
public int RelationTypeId
{
get { return _relationType.Id; }
}
public int RelationTypeId => _relationType.Id;
}
}
+10 -23
View File
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private class PropertySelectors
{
public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<RelationType, string>(x => x.Name);
public readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo<RelationType, string>(x => x.Alias);
public readonly PropertyInfo IsBidirectionalSelector = ExpressionHelper.GetPropertyInfo<RelationType, bool>(x => x.IsBidirectional);
public readonly PropertyInfo ParentObjectTypeSelector = ExpressionHelper.GetPropertyInfo<RelationType, Guid>(x => x.ParentObjectType);
public readonly PropertyInfo ChildObjectTypeSelector = ExpressionHelper.GetPropertyInfo<RelationType, Guid>(x => x.ChildObjectType);
}
/// <summary>
/// Gets or sets the Name of the RelationType
/// </summary>
[DataMember]
public string Name
{
get { return _name; }
set { SetPropertyValueAndDetectChanges(value, ref _name, Ps.Value.NameSelector); }
get => _name;
set => SetPropertyValueAndDetectChanges(value, ref _name, nameof(Name));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
/// <summary>
@@ -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));
}
}
+18 -21
View File
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private class PropertySelectors
{
public readonly PropertyInfo ServerAddressSelector = ExpressionHelper.GetPropertyInfo<ServerRegistration, string>(x => x.ServerAddress);
public readonly PropertyInfo ServerIdentitySelector = ExpressionHelper.GetPropertyInfo<ServerRegistration, string>(x => x.ServerIdentity);
public readonly PropertyInfo IsActiveSelector = ExpressionHelper.GetPropertyInfo<ServerRegistration, bool>(x => x.IsActive);
public readonly PropertyInfo IsMasterSelector = ExpressionHelper.GetPropertyInfo<ServerRegistration, bool>(x => x.IsMaster);
}
/// <summary>
/// Initializes a new instance of the <see cref="ServerRegistration"/> class.
/// </summary>
@@ -73,8 +62,8 @@ namespace Umbraco.Core.Models
/// </summary>
public string ServerAddress
{
get { return _serverAddress; }
set { SetPropertyValueAndDetectChanges(value, ref _serverAddress, Ps.Value.ServerAddressSelector); }
get => _serverAddress;
set => SetPropertyValueAndDetectChanges(value, ref _serverAddress, nameof(ServerAddress));
}
/// <summary>
@@ -82,8 +71,8 @@ namespace Umbraco.Core.Models
/// </summary>
public string ServerIdentity
{
get { return _serverIdentity; }
set { SetPropertyValueAndDetectChanges(value, ref _serverIdentity, Ps.Value.ServerIdentitySelector); }
get => _serverIdentity;
set => SetPropertyValueAndDetectChanges(value, ref _serverIdentity, nameof(ServerIdentity));
}
/// <summary>
@@ -91,8 +80,8 @@ namespace Umbraco.Core.Models
/// </summary>
public bool IsActive
{
get { return _isActive; }
set { SetPropertyValueAndDetectChanges(value, ref _isActive, Ps.Value.IsActiveSelector); }
get => _isActive;
set => SetPropertyValueAndDetectChanges(value, ref _isActive, nameof(IsActive));
}
/// <summary>
@@ -100,19 +89,27 @@ namespace Umbraco.Core.Models
/// </summary>
public bool IsMaster
{
get { return _isMaster; }
set { SetPropertyValueAndDetectChanges(value, ref _isMaster, Ps.Value.IsMasterSelector); }
get => _isMaster;
set => SetPropertyValueAndDetectChanges(value, ref _isMaster, nameof(IsMaster));
}
/// <summary>
/// Gets the date and time the registration was created.
/// </summary>
public DateTime Registered { get { return CreateDate; } set { CreateDate = value; }}
public DateTime Registered
{
get => CreateDate;
set => CreateDate = value;
}
/// <summary>
/// Gets the date and time the registration was last accessed.
/// </summary>
public DateTime Accessed { get { return UpdateDate; } set { UpdateDate = value; }}
public DateTime Accessed
{
get => UpdateDate;
set => UpdateDate = value;
}
/// <summary>
/// Converts the value of this instance to its equivalent string representation.
+4 -13
View File
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private class PropertySelectors
{
public readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo<StylesheetProperty, string>(x => x.Alias);
public readonly PropertyInfo ValueSelector = ExpressionHelper.GetPropertyInfo<StylesheetProperty, string>(x => x.Value);
}
/// <summary>
/// The CSS rule name that can be used by Umbraco in the back office
/// </summary>
@@ -43,8 +34,8 @@ namespace Umbraco.Core.Models
/// </summary>
public string Alias
{
get { return _alias; }
set { SetPropertyValueAndDetectChanges(value, ref _alias, Ps.Value.AliasSelector); }
get => _alias;
set => SetPropertyValueAndDetectChanges(value, ref _alias, nameof(Alias));
}
/// <summary>
@@ -52,8 +43,8 @@ namespace Umbraco.Core.Models
/// </summary>
public string Value
{
get { return _value; }
set { SetPropertyValueAndDetectChanges(value, ref _value, Ps.Value.ValueSelector); }
get => _value;
set => SetPropertyValueAndDetectChanges(value, ref _value, nameof(Value));
}
}
+3 -15
View File
@@ -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<Tag, string>(x => x.Group);
public readonly PropertyInfo Text = ExpressionHelper.GetPropertyInfo<Tag, string>(x => x.Text);
public readonly PropertyInfo LanguageId = ExpressionHelper.GetPropertyInfo<Tag, int?>(x => x.LanguageId);
}
/// <inheritdoc />
public string Group
{
get => _group;
set => SetPropertyValueAndDetectChanges(value, ref _group, Selectors.Group);
set => SetPropertyValueAndDetectChanges(value, ref _group, nameof(Group));
}
/// <inheritdoc />
public string Text
{
get => _text;
set => SetPropertyValueAndDetectChanges(value, ref _text, Selectors.Text);
set => SetPropertyValueAndDetectChanges(value, ref _text, nameof(Text));
}
/// <inheritdoc />
public int? LanguageId
{
get => _languageId;
set => SetPropertyValueAndDetectChanges(value, ref _languageId, Selectors.LanguageId);
set => SetPropertyValueAndDetectChanges(value, ref _languageId, nameof(LanguageId));
}
/// <inheritdoc />
+8 -19
View File
@@ -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<int> _masterTemplateId;
private static readonly Lazy<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private class PropertySelectors
{
public readonly PropertyInfo MasterTemplateAliasSelector = ExpressionHelper.GetPropertyInfo<Template, string>(x => x.MasterTemplateAlias);
public readonly PropertyInfo MasterTemplateIdSelector = ExpressionHelper.GetPropertyInfo<Template, Lazy<int>>(x => x.MasterTemplateId);
public readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo<Template, string>(x => x.Alias);
public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo<Template, string>(x => x.Name);
}
public Template(string name, string alias)
: this(name, alias, (Func<File, string>) null)
{ }
@@ -42,28 +31,28 @@ namespace Umbraco.Core.Models
[DataMember]
public Lazy<int> 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));
}
/// <summary>
+7 -20
View File
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private class PropertySelectors
{
public readonly PropertyInfo ContentSelector = ExpressionHelper.GetPropertyInfo<UmbracoDomain, int?>(x => x.RootContentId);
public readonly PropertyInfo DefaultLanguageSelector = ExpressionHelper.GetPropertyInfo<UmbracoDomain, int?>(x => x.LanguageId);
public readonly PropertyInfo DomainNameSelector = ExpressionHelper.GetPropertyInfo<UmbracoDomain, string>(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("*");
/// <summary>
/// Readonly value of the language ISO code for the domain
@@ -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<PropertySelectors> Ps = new Lazy<PropertySelectors>();
private class PropertySelectors
{
public readonly PropertyInfo WriterSelector = ExpressionHelper.GetPropertyInfo<Content, string>(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; }