C# 5.0: More Than Just Async: Listing 2.
Using the new CallerMemberName property.
public class Foo : INotifyPropertyChanged
{
private int employeeCount;
public event PropertyChangedEventHandler PropertyChanged;
public int EmployeeCount
{
get { return employeeCount; }
set
{
if (value != employeeCount)
{
employeeCount = value;
NotifyPropertyChanged();
}
}
}
public void NotifyPropertyChanged([CallerMemberName] string property = null)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
}
}
About the Author
Patrick Steele is a senior .NET developer with Billhighway in Troy, Mich. A recognized expert on the Microsoft .NET Framework, he’s a former Microsoft MVP award winner and a presenter at conferences and user group meetings.