今天研究了一下获取委托链的方式,发现通过Events只能获取特定事件的委托,对于一些自定义或者非事件类的委托不完全有效,下面是我的研究成果:
public static Delegate[] GetDelegate<T>(this T t, string strDelegateName)
{
FieldInfo fieldInfo = typeof(T).GetField(strDelegateName,
BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
if (fieldInfo == null) return null;
object o = fieldInfo.GetValue(t);
MulticastDelegate dele = o as MulticastDelegate;
if (o == null) return null;
return dele.GetInvocationList();
}