当前位置: 首页>>代码示例>>C#>>正文


C# Action.GetMethodInfo方法代码示例

本文整理汇总了C#中System.Action.GetMethodInfo方法的典型用法代码示例。如果您正苦于以下问题:C# Action.GetMethodInfo方法的具体用法?C# Action.GetMethodInfo怎么用?C# Action.GetMethodInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Action的用法示例。


在下文中一共展示了Action.GetMethodInfo方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WeakAction

 public WeakAction(Action action)
 {
     action.ThrowIfNull("action");
     _method = action.GetMethodInfo();
     if (action.GetMethodInfo().IsStatic)
     {
         _staticAction = action;
     }
     if (action.Target != null)
     {
         _actionTargetReference = new WeakReference(action.Target);
     }
 }
开发者ID:ryanhorath,项目名称:Rybird.Framework,代码行数:13,代码来源:WeakAction.cs

示例2: RegisterStaticEvent

 /// <summary>Registers a static event on the given target object. </summary>
 /// <param name="type">The target type. </param>
 /// <param name="eventName">The event name. </param>
 /// <param name="callback">The callback. </param>
 /// <returns>The registration token to deregister the event. </returns>
 public static object RegisterStaticEvent(Type type, string eventName, Action<object, object> callback)
 {
     var callbackMethodInfo = callback.GetMethodInfo();
     var eventInfo = type.GetRuntimeEvent(eventName);
     var callbackDelegate = callbackMethodInfo.CreateDelegate(eventInfo.EventHandlerType, callback.Target);
     return eventInfo.AddMethod.Invoke(null, new object[] { callbackDelegate });
 }
开发者ID:yukiyuki,项目名称:MyToolkit,代码行数:12,代码来源:EventUtilities.cs

示例3: CreateInvocationThatThrows

        private IInvocation CreateInvocationThatThrows()
        {
            var array = new[]
                        {
                            1,
                            2
                        };

            var arguments = new object[]
                            {
                                array
                            };
            var action = new Action(DoesThrow);
            var invocation = Substitute.For <IInvocation>();
            invocation.TargetType.Returns(typeof ( LogAspectTests ));
            invocation.Method.Returns(action.GetMethodInfo());
            invocation.Arguments.Returns(arguments);
            invocation.When(x => x.Proceed())
                      .Do(x =>
                          {
                              DoesThrow();
                          });

            return invocation;
        }
开发者ID:tschroedter,项目名称:Selkie.Aop,代码行数:25,代码来源:LogAspectTests.cs

示例4: WeakRelayCommand

 public WeakRelayCommand(Action<object> executeCallback, Func<object, bool> canExecuteCallback = null)
 {
     ExecuteTargetReference = new WeakReference<object>(executeCallback.Target);
     if (canExecuteCallback != null)
         CanExecuteTargetReference = new WeakReference<object>(canExecuteCallback.Target);
     ExecuteCallbackInfo = executeCallback.GetMethodInfo();
     CanExecuteCallbackInfo = canExecuteCallback?.GetMethodInfo();
 }
开发者ID:AlexKven,项目名称:OneAppAway-RTM,代码行数:8,代码来源:WeakRelayCommand.cs

示例5: WeakAction

        public WeakAction(object target, Action action)
        {
            #if NETFX_CORE
            if (action.GetMethodInfo().IsStatic)
            #else
            if (action.Method.IsStatic)
            #endif
            {
                _staticAction = action;

                if (target != null)
                {
                    // Keep a reference to the target to control the
                    // WeakAction's lifetime.
                    Reference = new WeakReference(target);
                }

                return;
            }

            #if SILVERLIGHT
            if (!action.Method.IsPublic
                || (action.Target != null
                    && !action.Target.GetType().IsPublic
                    && !action.Target.GetType().IsNestedPublic))
            {
                _action = action;
            }
            else
            {
                var name = action.Method.Name;

                if (name.Contains("<")
                    && name.Contains(">"))
                {
                    // Anonymous method
                    _action = action;
                }
                else
                {
                    Method = action.Method;
                    ActionReference = new WeakReference(action.Target);
                }
            }
            #else
            #if NETFX_CORE
            Method = action.GetMethodInfo();
            #else
            Method = action.Method;
            #endif
            ActionReference = new WeakReference(action.Target);
            #endif

            Reference = new WeakReference(target);
        }
开发者ID:Denver140390,项目名称:VeeamFileExplorer,代码行数:55,代码来源:WeakAction.cs

示例6: WeakAction

        public WeakAction(object target, Action action)
        {
            if (action.GetMethodInfo().IsStatic)
            {
                _staticAction = action;

                if (target != null)
                {
                    // Keep a reference to the target to control the
                    // WeakAction's lifetime.
                    Reference = new WeakReference(target);
                }

                return;
            }

            Method = action.GetMethodInfo();
            ActionReference = new WeakReference(action.Target);
            Reference = new WeakReference(target);
        }
开发者ID:LionFree,项目名称:Cush,代码行数:20,代码来源:WeakAction.cs

示例7: Run

        public static void Run(this ApplicationInstance applicationInstance,
                               Action staticMethodToExecute, 
            TestInjectorSettings testInjectorSettings = null)
        {
            var methodInfo =
            #if NET40
                staticMethodToExecute.Method;
            #else
                staticMethodToExecute.GetMethodInfo();
            #endif
            if (!methodInfo.IsStatic)
                throw new InvalidOperationException("Method must be static - don't reference any outside parameters");

            RunMethodImpl(applicationInstance, methodInfo, testInjectorSettings);
        }
开发者ID:kiwidev,项目名称:testinjector,代码行数:15,代码来源:ApplicationInstanceExtensions.cs

示例8: AddEventHandler

		/// <summary>
		/// Subscribes the event handler.
		/// </summary>
		/// <param name="eventInfo">The event information.</param>
		/// <param name="item">The item.</param>
		/// <param name="action">The action.</param>
		private void AddEventHandler(EventInfo eventInfo, object item, Action action)
		{
			//Got inspiration from here: http://stackoverflow.com/questions/9753366/subscribing-an-action-to-any-event-type-via-reflection
			//Maybe it is possible to pass Event arguments as CommanParameter

			var mi = eventInfo.EventHandlerType.GetRuntimeMethods().First(rtm => rtm.Name == "Invoke");
			List<ParameterExpression> parameters = mi.GetParameters().Select(p => Expression.Parameter(p.ParameterType)).ToList();
			MethodInfo actionMethodInfo = action.GetMethodInfo();
			Expression exp = Expression.Call(Expression.Constant(this), actionMethodInfo, null);
			this.handler = Expression.Lambda(eventInfo.EventHandlerType, exp, parameters).Compile();
			eventInfo.AddEventHandler(item, handler);
		}
开发者ID:pacificIT,项目名称:Xamarin.Forms.Behaviors,代码行数:18,代码来源:EventToCommand.cs

示例9: AddTestCases

 private void AddTestCases(IList<TestCase>/*!*/ cases, Action/*!*/ testMethod)
 {
     var attrs = testMethod.GetMethodInfo().GetCustomAttributes<OptionsAttribute>();
     if (attrs.Any()) {
         foreach (OptionsAttribute options in attrs) {
             cases.Add(new TestCase {
                 Name = testMethod.GetMethodInfo().Name,
                 TestMethod = testMethod,
                 Options = options,
             });
         }
     } else {
         cases.Add(new TestCase {
             Name = testMethod.GetMethodInfo().Name,
             TestMethod = testMethod,
             Options = new OptionsAttribute(),
         });
     }
 }
开发者ID:TerabyteX,项目名称:main,代码行数:19,代码来源:Driver.cs

示例10: WeakAction

 /// <summary>
 /// Initializes a new instance of the <see cref="WeakAction"/> class.
 /// </summary>
 /// <param name="target">The action's owner.</param>
 /// <param name="action">The action.</param>
 public WeakAction(object target, Action action)
 {
     Method = action.GetMethodInfo();
     ActionReference = new WeakReference(action.Target);
     Reference = new WeakReference(target);
 }
开发者ID:HimanshPal,项目名称:Cimbalino-Toolkit,代码行数:11,代码来源:WeakAction.cs


注:本文中的System.Action.GetMethodInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。