c# - FieldInfo returning null on Component -
this question has answer here:
- addeventhandler using reflection 3 answers
i'm trying list of events of bindingsource , returning null code:
// bs bindingsource propertyinfo propertyinfo = bs.gettype() .getproperty("events", bindingflags.nonpublic | bindingflags.static | bindingflags.instance | bindingflags.flattenhierarchy); eventhandlerlist eventhandlerlist = propertyinfo .getvalue(bs, new object[] { }) eventhandlerlist; // following line returns null fieldinfo fieldinfo = typeof(bindingsource) .getfield("addingnew", bindingflags.instance | bindingflags.flattenhierarchy | bindingflags.instance | bindingflags.public | bindingflags.nonpublic);
i put possible bindingflags error persists. doing wrong?
found better answer duplicate addeventhandler using reflection - use type.getevent.
addingnew event, manipulate need corresponding auto-generated methods - "remove_{eventname}" , "add_{eventname}":
var add = typeof(system.windows.forms.bindingsource).getmethod("add_addingnew");
proper way use getevent
:
var adding = typeof(system.windows.forms.bindingsource).getevent("addingnew");
see how events implemented details on how events implemented.
Comments
Post a Comment