Initial commit of refactor of better/more efficient in terms of mem and performance properpty selectors for our models, this also yields a much cleaner syntax. I have discovered one issue now which is that the PropertyChanged event now fires before the property value is actually set, this is why the lambda syntax existed before. Instead we can use a ref property for the SetPropertyValueAndDetectChanges methods which will work much nicer - and also potentially have less allocations.
This commit is contained in:
@@ -21,8 +21,13 @@ namespace Umbraco.Core.Models
|
||||
IsoCode = isoCode;
|
||||
}
|
||||
|
||||
private static readonly PropertyInfo IsoCodeSelector = ExpressionHelper.GetPropertyInfo<Language, string>(x => x.IsoCode);
|
||||
private static readonly PropertyInfo CultureNameSelector = ExpressionHelper.GetPropertyInfo<Language, string>(x => x.CultureName);
|
||||
private static readonly Lazy<PropertySelectors> Ps = new Lazy<PropertySelectors>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Iso Code for the Language
|
||||
@@ -31,14 +36,7 @@ namespace Umbraco.Core.Models
|
||||
public string IsoCode
|
||||
{
|
||||
get { return _isoCode; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_isoCode = value;
|
||||
return _isoCode;
|
||||
}, _isoCode, IsoCodeSelector);
|
||||
}
|
||||
set { _isoCode = SetPropertyValueAndDetectChanges(value, _isoCode, Ps.Value.IsoCodeSelector); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -48,14 +46,7 @@ namespace Umbraco.Core.Models
|
||||
public string CultureName
|
||||
{
|
||||
get { return _cultureName; }
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_cultureName = value;
|
||||
return _cultureName;
|
||||
}, _cultureName, CultureNameSelector);
|
||||
}
|
||||
set { _cultureName = SetPropertyValueAndDetectChanges(value, _cultureName, Ps.Value.CultureNameSelector); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user