今天研究了一下获取委托链的方式,发现通过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();
        }

相关文章:

  • 2022-03-07
  • 2021-11-02
  • 2021-10-25
  • 2021-10-07
  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
  • 2022-03-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2022-03-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案