link中如何遍历一个事件中所有的方法,遍历事件的方法是用发射么?
1条回答 默认 最新
- threenewbee 2015-05-01 03:32关注
public static Delegate[] GetObjectEventList(object p_Object, string p_EventName, Type p_EventType)
{
PropertyInfo _PropertyInfo = p_Object.GetType().GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
if (_PropertyInfo != null)
{
object _EventList = _PropertyInfo.GetValue(p_Object, null);
if (_EventList != null && _EventList is EventHandlerList)
{
EventHandlerList _List = (EventHandlerList)_EventList;
FieldInfo _FieldInfo = p_EventType.GetField(p_EventName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
if (_FieldInfo == null) return null;
Delegate _ObjectDelegate = _List[_FieldInfo.GetValue(p_Object)];
if (_ObjectDelegate == null) return null;
return _ObjectDelegate.GetInvocationList();
}
}
return null;
}
用反射本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报