本文整理汇总了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);
}
}
示例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 });
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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(),
});
}
}
示例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);
}