forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEtwActivityReverterMethodInvoker.cs
More file actions
73 lines (55 loc) · 1.75 KB
/
Copy pathEtwActivityReverterMethodInvoker.cs
File metadata and controls
73 lines (55 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#if !UNIX
//-----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace System.Management.Automation.Tracing
{
using System;
internal class EtwActivityReverterMethodInvoker :
IMethodInvoker
{
#region Instance Data
private readonly IEtwEventCorrelator _eventCorrelator;
private readonly Func<Guid, Delegate, object[], object> _invoker;
#endregion
#region Creation/Cleanup
public EtwActivityReverterMethodInvoker(IEtwEventCorrelator eventCorrelator)
{
if (eventCorrelator == null)
{
throw new ArgumentNullException("eventCorrelator");
}
_eventCorrelator = eventCorrelator;
_invoker = DoInvoke;
}
#endregion
#region Instsance Access
public Delegate Invoker
{
get { return _invoker; }
}
public object[] CreateInvokerArgs(Delegate methodToInvoke, object[] methodToInvokeArgs)
{
// See DoInvoke method for what these args mean.
var retInvokerArgs = new object[]
{
_eventCorrelator.CurrentActivityId,
methodToInvoke,
methodToInvokeArgs,
};
return retInvokerArgs;
}
#endregion
#region Instance Utilities
private object DoInvoke(Guid relatedActivityId, Delegate method, object[] methodArgs)
{
using (_eventCorrelator.StartActivity(relatedActivityId))
{
return method.DynamicInvoke(methodArgs);
}
}
#endregion
}
}
#endif