CallerMemberName in an extension (INotifyPropertyChanged)
I am currently implementing an Extension for the INotifiyPropertyChanged
interface, you can read this:
INotifyPropertyChanged - Event stays null
for furhter information.
Now I would like to extend this extension further so that I dont need to
state the MemberExpression and when calling it from inside a set that the
CallerMemberName Attribute does the rest.
So I have tried to do the following (based on the links provided in my
last stackoverflow question):
public static void Notify(this PropertyChangedEventHandler EventHandler,
object sender,
[CallerMemberName] String propertyName = "")
{
if (EventHandler != null)
{
EventHandler(sender, new PropertyChangedEventArgs(propertyName));
}
}
This allows me to call the method like this:
this.PropertyChanged.Notify(this); //with CallerMemberName
this.PropertyChanged.Notify(this, "RandomProperty");
Now I would like to remove the neccessarity to always write the (this, ..)
parameter and just call it like so:
this.PropertyChanged.Notify(); //with CallerMemberName
this.PropertyChanged.Notify("RandomProperty");
How is this possible?
No comments:
Post a Comment