PostSharpAPI ReferencePost­Sharp.​Patterns.​ModelNotify­Property­Changed­Attribute
Open sandboxFocus

NotifyPropertyChangedAttribute Class

Custom attribute that, when applied on a type, implements the INotifyPropertyChanged interface for this class and all children classes.

Inheritance
NotifyPropertyChangedAttribute
Namespace: PostSharp.Patterns.Model
Assembly: PostSharp.Patterns.Model.dll
Syntax
[MulticastAttributeUsage]
[ProvideAspectRole("DataBinding")]
[AspectRoleDependency]
[AspectRoleDependency]
[AspectRoleDependency]
[AspectTypeDependency]
[AspectRoleDependency]
[AspectRoleDependency]
[Metric("UsedFeatures", "PostSharp.Patterns.Model.NotifyPropertyChanged")]
[IntroduceInterface]
[IntroduceInterface]
[IntroduceInterface]
[HasConstraint]
[Serializer]
public sealed class NotifyPropertyChangedAttribute : InstanceLevelAspect, ITypeLevelAspect, ITypeLevelAspectBuildSemantics, IAspectBuildSemantics, IValidableAnnotation, ICloneAwareAspect, IInstanceScopedAspect, ISerializationCallback, INotifyChildPropertyChanged, IAdviceProvider, IAspect, IQueryInterface, IDynamicInterfaceImplementation, ILicensedAspect
Remarks

The aspect analyzes dependencies between property getters and fields. The aspect understands indirect dependencies. For instance, a property getter may depend on several other methods or property getters, which in turn can depend on other methods or fields. The algorithm is not able to analyze calls to virtual methods or delegates (because of prohibitive computational cost), and will only try to analyze methods in the current class.

The aspect will emit a build-time error if it is not able to understand the code of the target class. In this case, you can exclude the property from automatic change notification by applying the IgnoreAutoChangeNotificationAttribute custom attribute to the problematic property, or SafeForDependencyAnalysisAttribute to ignore the warnings of the dependency analysis engine. You will then need to specify dependencies explicitly using the Depends class. You can also mark a helper method with the PureAttribute to make it safe from use in a property getter. For instance, the string.Format method is pure.

By default, the NotifyPropertyChangedAttribute aspect holds weak references to the client delegates. This behavior prevents memory leaks if client delegates are not properly removed before client objects are disposed. To cause the aspect to store strong references, set WeakEventStrategy property to AlwaysStrong when applying the aspect.

Target classes can customize the NotifyPropertyChangedAttribute aspect by implementing the OnPropertyChanged(string) method manually. If this method is implemented, it must be protected or public.

By default, the NotifyPropertyChangedAttribute aspect does not call property getters by itself in order to avoid unexpected side-effects. However, this means that there are false positive notifications of property change. To allow aspect to use arbitrary calls to property getters to suppress false positives, set the PreventFalsePositives property to true.

Constructors

Name Description
NotifyPropertyChangedAttribute()

Initializes a new instance of the NotifyPropertyChangedAttribute class that stores strong references to the client delegates.

NotifyPropertyChangedAttribute(PortableFormatterConstructorContext)

Fields

Name Description
BaseQueryInterface
LocationBindings
OnChildPropertyChangedMethod
OnChildPropertyChangingMethod
OnPropertyChangedMethod
OnPropertyChangedMethodOriginal
OnPropertyChangingMethod
PropertyLocationBindings
QueryInterfaceMethod

Properties

Name Description
AdvisedObject
ExcludeExplicitProperties

Determines whether the aspect should instrument only automatic properties and ignore any other. This mode allows to use only the abilities of PostSharp Essentials, and prevent the aspect from consuming premium features.

PreventFalsePositives

Determines whether the aspect should do additional efforts to prevent the PropertyChanged event from being raised when the value itself did not change. The default value of this property is false, which means that the aspect will raise the PropertyChanged event whenever any dependency of the property has changed, whether the property value has eventually changed or not. Setting this property to true consumes more memory and processing power because the aspect will need to evaluate the properties and store their value.

WeakEventStrategy

Determines how the PropertyChanged event behaves in terms of keeping weak or strong references.

Methods

Name Description
CompileTimeInitialize(Type, AspectInfo)

Method invoked at build time to initialize the instance fields of the current aspect. This method is invoked before any other build-time method.

CompileTimeValidate(Type)

Method invoked at build time to ensure that the aspect has been applied to the right target.

CreateInstance(AdviceArgs)

Creates a new instance of the aspect based on the current instance, serving as a prototype.

Finalize()

Destructor.

InitializeAspectInstance(AspectInitializationReason)
OnChildPropertyChanged(PropertyPath, Boolean)
OnChildPropertyChanging(PropertyPath, Boolean)
OnCloned(ICloneAwareAspect)

Method called after the an object enhanced by the current aspect has been cloned using System.Object.MemberwiseClone(). The this parameter refers to the new aspect instance in the cloned object.

OnFieldSet<T>(ILocationBinding<T>, Object, T, DeclarationIdentifier)
OnInstanceConstructed()
OnMethodEntry(MethodExecutionArgs)
OnMethodExit(MethodExecutionArgs)
OnMethodResume(MethodExecutionArgs)
OnMethodYield(MethodExecutionArgs)
OnPropertyChanged(String)
OnPropertyGet<T>(ILocationBinding<T>, Object, out T, DeclarationIdentifier)
QueryInterface(Type)
QueryInterface<T>()
RuntimeInitialize(Type)
RuntimeInitializeInstance()

Events

Name Description
ChildPropertyChanged
ChildPropertyChanging
PropertyChanged

Explicit Interface Implementations

Name Description
IAdviceProvider.ProvideAdvices(Object)

Provides an enumeration of advices, represented as instances of the AdviceInstance class, for the current aspect instance.

ILicensedAspect.GetLicenseRequirements()
ISerializationCallback.OnDeserialized()

Method called after the object has been deserialized.

ISerializationCallback.OnSerializing()