...
Code Block |
---|
[Serializable] [IntroduceInterface( typeof(INotifyPropertyChanged), OverrideAction = InterfaceOverrideAction.Ignore )] [MulticastAttributeUsage( MulticastTargets.Class, Inheritance = MulticastInheritance.Strict )] public sealed class NotifyPropertyChangedAttribute : InstanceLevelAspect, INotifyPropertyChanged { [ImportMember( "OnPropertyChanged", IsRequired = false )] public Action<string> BaseOnPropertyChanged; [IntroduceMember( Visibility = Visibility.Family, IsVirtual = true, OverrideAction = MemberOverrideAction.Ignore )] public void OnPropertyChanged( string propertyName ) { if ( this.PropertyChanged != null ) { this.PropertyChanged( this.Instance, new PropertyChangedEventArgs( propertyName ) ); } } [IntroduceMember( OverrideAction = MemberOverrideAction.Ignore )] public event PropertyChangedEventHandler PropertyChanged; [OnLocationSetHandler, MulticastSelector( Targets = MulticastTargets.Property )] public void OnPropertySet( LocationInterceptionArgs args ) { if ( args.Value == args.GetCurrentValue() ) return; if ( this.BaseOnPropertyChanged != null ) { this.BaseOnPropertyChanged( args.Location.PropertyInfo.Name ); } else { this.OnPropertyChanged( args.Location.PropertyInfo.Name ); } } } |
...
I added a test solution to https://repos.deltares.nl/repos/delft-tools/trunk/sandbox/PostSharp2
to play around with the new post sharp.
Gael introducing the attribute : http://www.postsharp.org/blog/introducing-postsharp-20-1-notifypropertychanged