c# - PostSharp & classes that (are supposed to) implement INotifyPropertyChanged -


i'm new postsharp , trying figure out whether can make life implementing property changed events bit easier. however, i'm facing first issue already. have interfaces in 1 project library, interfaces.dll:

public interface iperson : inotifypropertychanged {   string firstname { get; set; } } 

and implementation in one, implementations.dll :

[notifypropertychanged] // postsharp attribute public class person : iperson {   public string firstname { get; set; } } 

however, doesn't compile postsharp interjects code after compilation, inotifypropertychanged implementation missing @ compile time , hence, aborts error.

i'm aware set interface iperson without dependency on inotifypropertychanged , work intended, isn't pretty bad code then? of course (or rather, postsharp) implement inotifypropertychanged methods when set correctly, there no formal definition iperson must implement this, it'd possible create implementation without this, lead odd , potentially hard-to-trace errors. , whenever want use inotifypropertychanged methods, i'd have cast person type expiclitly, without having guarantees implement interface.

i'm aware implement propertychanged handler in person myself, , postsharp @ least take care of raising event. again i'm using postsharp sole purpose of managing itself, have start coding half of stuff again myself, i'm not sure it'd worth using.

so how guys handle this? there best practice this?

if class implements inotifypropertychange postsharp requires onpropertychanged present in class , expects implement on own.

edit: implementation of onpropertychanged this:

[notifypropertychanged] public class person : iperson {     public event propertychangedeventhandler propertychanged;      protected virtual void onpropertychanged(string propertyname)     {         propertychanged(this, new propertychangedeventargs(propertyname));     } } 

postsharp cannot raise event universally because of cli limitations. has use workaround.

notifypropertychanged can applied interfaces - interface implementations implement inotifypropertychanged:

[notifypropertychanged] public interface iperson ... public class person : iperson ... 

unfortunately have cast inotifypropertychange explicitly @ least can in safe way:

var person = new person(); post.cast<person, inotifypropertychanged>(person).propertychanged += ... 

there compile time error when person instance doesn't implement inotifypropertychanged , there no warning when does.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -