public override Action <TBaseType, TResult> OverrideSetter <TBaseType, TDeclaringType, TConstructedType, TResult>( PropertyInfo property) { //this code will run once per implementing property var propertyName = property.Name; var setter = PropertyImplementation <TBaseType, TDeclaringType> .GetSetter <TResult>(propertyName); var getter = PropertyImplementation <TBaseType, TDeclaringType> .GetGetter <TResult>(propertyName); var comparer = EqualityComparer <TResult> .Default; return((pthis, value) => { //constructed delegate will run every time accessing property. if (!comparer.Equals(value, getter(pthis))) { setter(pthis, value); pthis.OnPropertyChanged(new PropertyChangedEventArgs(propertyName)); } }); }
/// <summary> /// Overriding property setter implementation. /// </summary> /// <typeparam name="TBaseType">Base type for implementation. TBaseType must be TConcept, and inherits all its constraints. Also TBaseType is TDeclaringType.</typeparam> /// <typeparam name="TDeclaringType">Type, declaring property.</typeparam> /// <typeparam name="TConstructedType">Constructed type. TConstructedType is TDeclaringType and TBaseType.</typeparam> /// <typeparam name="TResult">Type of property.</typeparam> /// <param name="property">PropertyInfo of property.</param> /// <returns>Delegate, corresponding to property setter implementation.</returns> public override Action <TBaseType, TResult> OverrideSetter <TBaseType, TDeclaringType, TConstructedType, TResult>(PropertyInfo property) { var eventArgs = new PropertyChangedEventArgs(property.Name); //get delegates for base calls. Action <TBaseType, TResult> setter = PropertyImplementation <TBaseType, TDeclaringType> .GetSetter <TResult>(property.Name); Func <TBaseType, TResult> getter = PropertyImplementation <TBaseType, TDeclaringType> .GetGetter <TResult>(property.Name); var comparer = EqualityComparer <TResult> .Default; return((pthis, value) => { if (comparer.Equals(value, getter(pthis))) { return; } //base. call setter(pthis, value); //Directly accessing Concept's protected method. pthis.OnPropertyChanged(eventArgs); }); }
/// <summary> /// Overriding property setter implementation. /// </summary> /// <typeparam name="TBaseType">Base type for implementation. TBaseType must be TConcept, and inherits all its constraints. Also TBaseType is TDeclaringType.</typeparam> /// <typeparam name="TDeclaringType">Type, declaring property.</typeparam> /// <typeparam name="TConstructedType">Constructed type. TConstructedType is TDeclaringType and TBaseType.</typeparam> /// <typeparam name="TResult">Type of property.</typeparam> /// <param name="property">PropertyInfo of property.</param> /// <returns>Delegate, corresponding to property setter implementation.</returns> public override Action <TBaseType, TResult> OverrideSetter <TBaseType, TDeclaringType, TConstructedType, TResult>(PropertyInfo property) { //This code called once for each declared property on derived type's initialization. //EventArgs instance is shared between all events for each concrete property. var eventArgs = new PropertyChangedEventArgs(property.Name); //get delegates for base calls. Action <TBaseType, TResult> setter = PropertyImplementation <TBaseType, TDeclaringType> .GetSetter <TResult>(property.Name); Func <TBaseType, TResult> getter = PropertyImplementation <TBaseType, TDeclaringType> .GetGetter <TResult>(property.Name); var comparer = EqualityComparer <TResult> .Default; return((pthis, value) => { //This code executes each time property setter is called. if (comparer.Equals(value, getter(pthis))) { return; } //base. call setter(pthis, value); //Directly accessing Concept's protected method. pthis.OnPropertyChanged(eventArgs); }); }
public override Func <TBaseType, TResult> OverrideGetter <TBaseType, TDeclaringType, TConstructedType, TResult>( PropertyInfo property) { //this code will run once per implementing property return(PropertyImplementation <TBaseType, TDeclaringType> .GetGetter <TResult>(property.Name)); }
public override Func <TBaseType, TResult> OverrideGetter <TBaseType, TDeclaringType, TConstructedType, TResult>(PropertyInfo property) { return(PropertyImplementation <TBaseType, TDeclaringType> .GetGetter <TResult>(property.Name)); }