本文整理汇总了C#中System.Action.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Action.GetType方法的具体用法?C# Action.GetType怎么用?C# Action.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Action
的用法示例。
在下文中一共展示了Action.GetType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static Delegate Create(EventInfo eventInfo, Action action)
{
var handlerType = eventInfo.EventHandlerType;
var eventParameters = handlerType.GetMethod("Invoke").GetParameters();
var parameters = eventParameters.Select(p => Expression.Parameter(p.ParameterType, "x"));
var body = Expression.Call(Expression.Constant(action), action.GetType().GetMethod("Invoke"));
var lambda = Expression.Lambda(body, parameters.ToArray());
return Delegate.CreateDelegate(handlerType, lambda.Compile(), "Invoke", false);
}
示例2: RunAction
protected TimeSpan RunAction(Action action, int iterations, string actionName)
{
actionName = actionName ?? action.GetType().Name;
var ticksTaken = Measure(action, iterations);
var timeSpan = TimeSpan.FromSeconds(ticksTaken * 1d / Stopwatch.Frequency);
Log("{0} took {1}ms ({2} ticks), avg: {3} ticks", actionName, timeSpan.TotalMilliseconds, timeSpan.Ticks, (timeSpan.Ticks / iterations));
return timeSpan;
}
示例3: EventPropegator
public EventPropegator(object instance, EventInfo evt, Action<object, EventArgs> handler)
{
_instance = instance;
_evt = evt;
_disposed = false;
var methodInfo = handler.GetType().GetMethod("Invoke");
_delegate = Delegate.CreateDelegate(evt.EventHandlerType, handler, methodInfo);
evt.AddEventHandler(instance, _delegate);
}
示例4: VariableSubscription
public VariableSubscription(
VariableSubscriptionToken token,
Action<DebugEvaluationResult> executeAction,
Action<VariableSubscription> unsubscribeAction) {
Token = token;
_weakReference = new WeakReference(executeAction.Target);
_method = executeAction.Method;
_delegateType = executeAction.GetType();
_unsubscribe = unsubscribeAction;
}
示例5: AddEventHandler
public static void AddEventHandler(EventInfo eventInfo, object item, Action<object, EventArgs> action)
{
var parameters = eventInfo.EventHandlerType
.GetMethod("Invoke")
.GetParameters()
.Select(parameter => Expression.Parameter(parameter.ParameterType))
.ToArray();
var invoke = action.GetType().GetMethod("Invoke");
var handler = Expression.Lambda(
eventInfo.EventHandlerType,
Expression.Call(Expression.Constant(action), invoke, parameters[0], parameters[1]),
parameters
)
.Compile();
eventInfo.AddEventHandler(item, handler);
}
示例6: Add
public static void Add(DateTime executeTime, Action<string[]> action, string[] args)
{
DateTime now = DateTime.Now;
if (executeTime < DateTime.Now)
{
executeTime = now.AddSeconds(1.0);
}
Maticsoft.TimerTask.Model.TaskTimer timer2 = new Maticsoft.TimerTask.Model.TaskTimer {
IsSingle = true,
ExecuteType = action.GetType().FullName,
ExecuteTime = executeTime
};
TimeSpan span = (TimeSpan) (executeTime - now);
timer2.Interval = (decimal) span.TotalMilliseconds;
timer2.Params = args;
Maticsoft.TimerTask.Model.TaskTimer model = timer2;
model.ID = Maticsoft.TimerTask.BLL.TaskTimer.Add(model);
Instance().CurrentTasks.Add(new Maticsoft.TimerTask.Timer(model, executeTime, action, new Action<Maticsoft.TimerTask.Model.TaskTimer>(Task.CallBack), args));
}
示例7: createThread
// Accepts a method that does not return a value
// Creates a thread to run a function/method
private void createThread(Action method)
{
// Create the thread object, passing in a method
Thread aThread = new Thread(new ThreadStart(method));
try
{
// Add a name for the thread
aThread.Name = method.GetType().FullName.ToString();
// Start the thread
aThread.Start();
// Wait for thread to start
while (!aThread.IsAlive)
{
// Do nothing, but wait
}
// Wait for thread to finish
aThread.Join();
}
catch (System.Net.Mail.SmtpException ex)
{
// Wait for thread to finish
aThread.Join();
MessageBox.Show(ex.Message);
}
catch (Exception ex)
{
// Wait for thread to finish
aThread.Join();
throw ex;
}
}