public static bool Contains(this System.Delegate del, System.Type type, string methodName)
        {
            bool contains = false;

            if (del != null && del.GetInvocationList() != null)
            {
                contains = !System.Array.TrueForAll(del.GetInvocationList(), invoker => invoker.Method.DeclaringType != type && invoker.Method.Name != methodName);
            }
            return(contains);
        }
Example #2
0
 public static void CreateDelegate(ref System.Delegate self, System.Type type = null)
 {
     if (self != null)
     {
         foreach (var inv in self.GetInvocationList())
         {
             self = System.Delegate.Combine(self, System.Delegate.CreateDelegate(type ?? inv.Method.ReturnType, inv.Target, inv.Method));
         }
     }
 }
Example #3
0
        /// <summary>
        /// delegateの仕様上、targetのInvocationListは空になりませんので、戻り値を使用してください。
        /// <seealso cref="Hinode.Tests.CSharp.Extensions.TestDelegateExtensions.ClearInvocationsPasses()"/>
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public static System.Delegate ClearInvocations(this System.Delegate target)
        {
            if (target == null)
            {
                return(null);
            }
            var list = target.GetInvocationList();

            for (var i = 0; i < list.Length; ++i)
            {
                target = System.Delegate.Remove(target, list[i]);
            }
            return(target);
        }
Example #4
0
 public static bool HasDelegate(System.Delegate mainDelegate, System.Delegate targetListener)
 {
     if (mainDelegate != null)
     {
         if (mainDelegate.GetInvocationList().Contains(targetListener))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Example #5
0
 private bool OnPreProcess(ref Forms::Message msg)
 {
     System.Delegate ev = base.Events[EV_PRE_PROC];
     if (ev == null)
     {
         return(false);
     }
     System.Delegate[] delegs = ev.GetInvocationList();
     for (int i = delegs.Length - 1; i >= 0; i--)
     {
         WndProcEventHandler proc = (WndProcEventHandler)delegs[i];
         if (proc(this, ref msg))
         {
             return(true);
         }
     }
     return(false);
 }
Example #6
0
 /// <summary>
 /// 要求された名前を持つ文字処理関数を返します。
 /// 見つからない場合は null を返します。
 /// </summary>
 protected System.Delegate GetLetterHandlerEx(string key)
 {
     //--自分の所から呼び出し
     System.Delegate dlg = this.hLttr[key] as System.Delegate;
     if (dlg != null)
     {
         LetterHandler2Txt[] ary = (LetterHandler2Txt[])dlg.GetInvocationList();
         return(ary[ary.Length - 1]);
     }
     //--継承元からの呼び出し
     foreach (Context2Txt c in this.implements)
     {
         dlg = c.GetLetterHandlerEx(key);
         if (dlg != null)
         {
             return(dlg);
         }
     }
     return(null);
 }
Example #7
0
        public static System.Delegate ConvertTo(this System.Delegate self, System.Type type)
        {
            if (type == null)
            {
                throw new System.ArgumentNullException("type");
            }
            if (self == null)
            {
                return(null);
            }

            if (self.GetType() == type)
            {
                return(self);
            }

            return(System.Delegate.Combine(
                       self.GetInvocationList()
                       .Select(i => System.Delegate.CreateDelegate(type, i.Target, i.Method))
                       .ToArray()));
        }
Example #8
0
        public void Test(System.Delegate a_Event, string a_EventName)
        {
            if (!test_enabled)
            {
                return;
            }
            if (a_Event == null)
            {
                return;
            }

            if (_HandlerCounts == null)
            {
                _HandlerCounts = new Dictionary <string, int>();
            }

            // Count handlers
            _listeners = a_Event.GetInvocationList();
            int listenCount = _listeners.Length;

            _HandlerCounts[a_EventName] = listenCount;
        }
Example #9
0
        public static bool IsRegistered <T1, T2>(System.Delegate source, System.Action <T1, T2> compare)
        {
            if (source == null || compare == null)
            {
                return(false);
            }

            System.Delegate[] delegates = source.GetInvocationList();
            if (delegates == null || delegates.Length == 0)
            {
                return(false);
            }

            for (int i = 0; i < delegates.Length; i++)
            {
                if (delegates[i].Equals(compare))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #10
0
 public static bool Contains(this System.Delegate @delegate, string methodName)
 {
     return(!System.Array.TrueForAll(@delegate.GetInvocationList(), invoker => invoker.Method.Name != methodName));
 }