如果我有一个包含一些属性和方法的类,当属性被更改时,它会触发一个事件(在这种情况下将一个字符串传递给args):
public class Settings
{
public delegate void SettingsChangedHandler(object sender, string e);
public event SettingsChangedHandler SettingsChanged;
private string rootfolder;
public string RootFolder
{
get { return rootfolder; }
set
{
rootfolder = value;
if (SettingsChanged != null)
SettingsChanged(this, "ROOT_FOLDER");
}
}
}
如果在我的法典中有某些地方:
public Settings SettingsInstance = new Settings();
SettingsInstance.SettingsChanged += new SettingsChangedHandler(SettingsInstance_SettingsChanged);
SettingsInstance = SomeOtherSettingsInstance;
我希望所有已经改变的房地产都对其事件开火。
我该如何实现类似这样的效果?我不用一个一个地复制吧?