本文整理汇总了C#中System.Action.GetInvocationList方法的典型用法代码示例。如果您正苦于以下问题:C# Action.GetInvocationList方法的具体用法?C# Action.GetInvocationList怎么用?C# Action.GetInvocationList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Action
的用法示例。
在下文中一共展示了Action.GetInvocationList方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderMenu
private static void RenderMenu(Action examples)
{
Console.WriteLine("Select an example:");
for (int i = 0; i < examples.GetInvocationList().Count(); i++)
{
var action = examples.GetInvocationList().ToArray()[i];
Console.WriteLine(" {0} - {1}", i, action.Method.DeclaringType.Name);
}
Console.Write(">");
}
示例2: AddTaskDelay
private static void AddTaskDelay(Action action, int delayInMilliseconds)
{
System.Threading.Thread.Sleep(delayInMilliseconds);
bool bFired;
if (action != null)
{
foreach (Delegate singleCast in action.GetInvocationList())
{
bFired = false;
try
{
ISynchronizeInvoke syncInvoke = (ISynchronizeInvoke)singleCast.Target;
if (syncInvoke != null && syncInvoke.InvokeRequired)
{
bFired = true;
syncInvoke.BeginInvoke(singleCast, null);
}
else
{
bFired = true;
singleCast.DynamicInvoke(null);
}
}
catch (Exception)
{
if (!bFired)
singleCast.DynamicInvoke(null);
}
}
}
}
示例3: IdentifySelection
private static int IdentifySelection(Action examples)
{
var selection = Console.ReadLine();
int index;
if (!int.TryParse(selection, out index))
{
// put it out of range
index = examples.GetInvocationList().Count();
}
return index;
}
示例4: Running
public Running(Action action)
{
this.action = action;
try
{
foreach (var action_delegate in action.GetInvocationList())
{
action_delegate.DynamicInvoke();
}
}
catch (Exception e)
{
exception = e.InnerException;
}
}
示例5: ExecuteDelegateExample
private static void ExecuteDelegateExample(Action examples, int selectedIndex)
{
var counter = 0;
foreach (Action action in examples.GetInvocationList())
{
if (counter.Equals(selectedIndex))
{
Console.WriteLine("{1}{0}{1}{2}", action.Method.DeclaringType, Environment.NewLine, new string('-', 20));
try
{
action();
}
catch (Exception exception)
{
Console.WriteLine(exception);
}
break;
}
counter++;
}
}
示例6: RaiseEvent
private void RaiseEvent(Action<string, byte[]> handler, string key, RedisResult value)
{
if (handler == null) return;
foreach (Action<string, byte[]> child in handler.GetInvocationList())
{
try
{
child(key, value.ValueBytes);
}
catch (Exception ex)
{
OnError("Subscriber callback", ex, false);
}
}
}
示例7: AddUnique
private Action AddUnique(Action listeners, Action callback)
{
if (!listeners.GetInvocationList().Contains(callback))
{
listeners += callback;
}
return listeners;
}
示例8: InvokeDuringEventWithBehaviorDecision
private static MethodBehaviors InvokeDuringEventWithBehaviorDecision(Action<DuringCallbackEventArgs> call, DuringCallbackEventArgs args)
{
if (call == null) {
return MethodBehaviors.IDontCare;
}
bool wasLastOptionChangedAtLeastOnce = false;
MethodBehaviors lastOption = args.MethodBehavior;
Aspect lastAspect = null;
Delegate[] list = call.GetInvocationList();
foreach (Delegate d2 in list) {
try {
Action<DuringCallbackEventArgs> invokeEvent = d2 as Action<DuringCallbackEventArgs>;
args.MethodBehavior = MethodBehaviors.IDontCare;
args.WasBehaviorSet = false;
invokeEvent(args);
bool wasRealBehaviorSet = args.WasBehaviorSet && args.MethodBehavior != MethodBehaviors.IDontCare;
bool isNewBehaviorConflictingWithOlderBehaviorRequest = wasRealBehaviorSet && lastOption != MethodBehaviors.IDontCare;
bool isThisTheFirstRealBehaviorSelection = wasRealBehaviorSet && !wasLastOptionChangedAtLeastOnce;
//var aspect = GetAspectHandledBy(invokeEvent);
if (isThisTheFirstRealBehaviorSelection) {
wasLastOptionChangedAtLeastOnce = true;
lastAspect = GetAspectHandledBy(invokeEvent);
lastOption = args.MethodBehavior;
continue;
}
if (isNewBehaviorConflictingWithOlderBehaviorRequest) {
Aspect currentAspect = GetAspectHandledBy(invokeEvent);
string msg = BuildConflictMessage(args, lastOption, lastAspect, currentAspect);
throw new ConflictingBehaviorException(msg);
}
if (args.MethodBehavior != MethodBehaviors.IDontCare) {
lastAspect = GetAspectHandledBy(invokeEvent);
lastOption = args.MethodBehavior;
}
}
catch (Exception e) {
args.MethodBehavior = MethodBehaviors.ThrowException;
args.ReturnValueOrException = e;
return MethodBehaviors.ThrowException;
}
}
return lastOption;
}
示例9: AddUnique
void AddUnique(ref Action listeners, Action callback) //ref because it's initially null
{
if (listeners == null || !listeners.GetInvocationList().Contains(callback)) {
listeners += callback;
}
}
示例10: RemoveAll
public static Action<Danmaku> RemoveAll(this Action<Danmaku> source, Action<Danmaku> toRemove) {
Delegate[] elements = toRemove.GetInvocationList();
foreach (var element in elements)
source = Delegate.Remove(source, element) as Action<Danmaku>;
return source;
}