I'd like to dynamically set a list of custom event handlers something like this in pseudo-code:
FieldInfo[] fieldInfos = this.GetType().GetFields(
BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
foreach (FieldInfo fieldInfo in fieldInfos)
{
if this.fieldInfo.GetType() = TypeOf(CustomEventHandler<this.fieldInfo.Name>) {
this.fieldInfo.Name += new CustomEventHandler<this.fieldInfo.Name>(OnChange<this.fieldInfo.Name>);
}
}
I can't find the right syntax can you ?
Use Type.GetEvents(), not GetFields(). You can then use EventInfo.AddEventHandler().
How about GetEvents instead of GetFields?
I'm not totally sure about the type-comparison, but then again,
fieldInfo.Name
can't be used in a generic like that.