I have a class that implements INotifyPropertyChanged and also has its own concept of properties, a little bit like this:
class sealed MyClass : INotifyPropertyChanged
{
private Dictionary<string, object> _properties;
public object GetProperty(string name)
{
return _properties[name];
}
public object SomeProperty
{
get
{
return GetProperty("SomeProperty");
}
}
}
Note that some common properties also have C# accessors.
I want to raise an event to notify others that a property (whose value is accessed through the GetProperty method) has changed even if this property does not have a corresponding C# accessor.
Assuming that there is no risk of a clash (i.e. inadvertantly raising a property changed event for a C# property whose value has not changed – note that this class is sealed), is there any reason why I can’t just use the INotifyPropertyChanged.PropertyChanged event to notify others, or should I add my own event for this purpose?
I would suggest that you add your own. Although there’s no specific reason that the code would break,
INotifyPropertyChangedhas a specific intended usage, and one that is understood by a lot of potential consumers. I’d not personally write code that contradicts that, just in case.