Below is not guaranteed to work, if we inline the set, GetCurrentMethod will 
return the wrong method.

From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On 
Behalf Of David Burela
Sent: Tuesday, March 22, 2011 7:57 PM
To: ozDotNet
Subject: Raising property changed events

Raising property changed events seems like something that most applications 
need to do at some stage. C#3 introduced the auto property i.e. public bool 
IsBusy { get; set; }
I am surprised that there isn't a way built into the framework to automatically 
raise changed events


Anyway, i saw this code used at a client site. it seems like a smart way to 
handle the raised event without using fragile strings that might not get 
updated when you change the property name

private bool isBusy;
public bool IsBusy
{
    get { return isBusy; }
    set
    {
        isDialogProcessing = value;
        
RaisePropertyChanged(System.Reflection.MethodBase.GetCurrentMethod().Name.Substring(4));
    }
}


Thought I'd throw it out there. See how other people are handling property 
changed events in their own projects.
I'm sure there is an AOP way of introducing them. But all the AOP demos I have 
watched seem to increase compilation times by heaps.

-David Burela

Reply via email to