Information Technology Reference
In-Depth Information
if ( value != mem)
{
if (PropertyChanging != null )
PropertyChanging( this ,
new PropertyChangingEventArgs (
"UsedMemory" ));
mem = value ;
if (PropertyChanged != null )
PropertyChanged( this ,
new PropertyChangedEventArgs (
"UsedMemory" ));
}
}
}
private long mem;
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler
PropertyChanged;
#endregion
#region INotifyPropertyChanging Members
public event PropertyChangingEventHandler
PropertyChanging;
#endregion
}
That's all there is to it. But, every time you create an implementation of
either of these interfaces, you'll ask yourself if there is an easier way to do
this. Every property setter needs to raise an event. There really isn't a good
way around that. But, you can see that every setter needs to raise two
events: one before it changes the property and one after. What's worse is
that the argument to the event parameters uses a string to represent the
property name. That's very brittle. Any refactoring is going to break this
code. Any typing mistakes create broken code. So let's make this easier,
and let's fix this.
The obvious choice is going to be implementing something in an extension
method. You're going to want to add these methods with any class that
implements INotifyPropertyChanged and INotifyPropertyChanging.
Search WWH ::




Custom Search