I'm new to PostSharp and am trying to figure out whether it can make my life implementing property changed events a bit easier. However, I'm facing the first issue already. I have my interfaces in one Project library, interfaces.dll:
public interface IPerson : INotifyPropertyChanged
{
string firstName { get; set; }
}
and the implementation in another one, implementations.dll :
[NotifyPropertyChanged] // Postsharp attribute
public class Person : IPerson
{
public string firstName { get; set; }
}
However, this doesn't compile as PostSharp only interjects is code after compilation, so the INotifyPropertyChanged implementation is missing at compile time and hence, that aborts with an error.
I'm aware I could just set up the interface IPerson without dependency on INotifyPropertyChanged and everything will work just as intended, but isn't this pretty bad code then? Of course I (or rather, postsharp) will implement the INotifyPropertyChanged methods by itself when set up correctly, but there is no formal definition that IPerson must implement this, so it'd be possible to create an implementation without this, which would lead to odd and potentially hard-to-trace errors. And whenever I want to use INotifyPropertyChanged methods, I'd have to cast Person to this type expiclitly, without having any guarantees it does actually implement the interface.
I'm also aware I could just implement the PropertyChanged handler in Person myself, and PostSharp would at least take care of raising the event. But then again I'm using PostSharp for the sole purpose of managing all that by itself, so it I have to start coding half of that stuff again by myself, I'm not sure it'd be worth using.
So how do you guys handle this? Is there any best practice for this?