예제 #1
0
        private static void DynamicInvokers(object[] animals)
        {
            var dynamicInvokers = new IDynamicInvoke <object>[]
            {
                new ReflectionDynamic <object>("Nop"),
                new SudoDynamic <object>("Nop"),
            };

            Stopwatch timer;

            foreach (IDynamicInvoke <object> invoker in dynamicInvokers)
            {
                timer = Stopwatch.StartNew();

                for (int i = 0; i < 1000000; i++)
                {
                    foreach (object o in animals)
                    {
                        invoker.Invoke(o);
                    }
                }

                timer.Stop();
                Console.WriteLine("{0} took {1}", invoker.GetType().Name, timer.Elapsed);
            }
        }
예제 #2
0
 private void propertyGrid_SelectedGridItemChanged(object sender, SelectedGridItemChangedEventArgs e)
 {
     if (propertyGrid.SelectedTab == this)
     {
         IDynamicInvoke dynInvoke = InvokableActiveItem();
         this.invokeMenuItem.Enabled = dynInvoke != null;
     }
 }
예제 #3
0
        private void OnInvokeEvent(object sender, EventArgs e)
        {
            IDynamicInvoke dynInvoke = InvokableActiveItem();

            if (dynInvoke != null)
            {
                dynInvoke.DynamicInvoke();
            }
        }
예제 #4
0
        public static IDynamicInvoke TryGetOrWrap(object target)
        {
            Validate.IsNotNull <object>(target, "target");
            IDynamicInvoke invoke = target as IDynamicInvoke;

            if (invoke != null)
            {
                return(invoke);
            }
            Type[]     types            = new Type[] { typeof(string), typeof(object[]) };
            MethodInfo invokeMethodInfo = target.GetType().GetMethod("OnInvokeDynamicMethod", BindingFlags.NonPublic | BindingFlags.Instance, null, types, null);

            if (invokeMethodInfo == null)
            {
                return(null);
            }
            return(new DynamicInvokeViaPrivateOnInvokeDynamicMethod(target, invokeMethodInfo));
        }