S
Simon
Hi folks,
I have an object library where there are base classes that have a
declared event. I have hit the problem where the derived class cannot
raise the event. After some thought I had the idea of declaring a
protected method in the base class to raise the event, so that the
derived class can just call this method when it needs to raise this event.
Is this good form, or is there a better way.
eg
public class myBaseClass {
public delegate void ChangedDelegate();
public event ChangedDelegate OnChanged;
protected void RaiseChangedEvent() {
if (OnChanged != null)
OnChanged();
}
}
public class myDerivedClass : myBaseClass {
private string _someValue;
public string SomeValue {
get { return _someValue; }
set {
if (_someValue != value)
RaiseChangedEvent();
_someValue = value;
}
}
I have an object library where there are base classes that have a
declared event. I have hit the problem where the derived class cannot
raise the event. After some thought I had the idea of declaring a
protected method in the base class to raise the event, so that the
derived class can just call this method when it needs to raise this event.
Is this good form, or is there a better way.
eg
public class myBaseClass {
public delegate void ChangedDelegate();
public event ChangedDelegate OnChanged;
protected void RaiseChangedEvent() {
if (OnChanged != null)
OnChanged();
}
}
public class myDerivedClass : myBaseClass {
private string _someValue;
public string SomeValue {
get { return _someValue; }
set {
if (_someValue != value)
RaiseChangedEvent();
_someValue = value;
}
}