/
IInvocation.cs
69 lines (49 loc) · 1.77 KB
/
IInvocation.cs
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
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
namespace WeihanLi.Common.Aspect;
public interface IInvocation
{
MethodInfo ProxyMethod { get; }
object ProxyTarget { get; }
MethodInfo? Method { get; }
object? Target { get; }
object[] Arguments { get; }
Type[] GenericArguments { get; }
object? ReturnValue { get; set; }
Dictionary<string, object?> Properties { get; }
}
public class AspectInvocation : IInvocation
{
public MethodInfo ProxyMethod { get; }
public object ProxyTarget { get; }
public MethodInfo? Method { get; }
public object? Target { get; }
public object[] Arguments { get; }
public Type[] GenericArguments { get; }
public object? ReturnValue { get; set; }
public Dictionary<string, object?> Properties { get; }
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")]
public AspectInvocation(
MethodInfo proxyMethod,
MethodInfo? methodBase,
object proxyTarget,
object? target,
object[] arguments)
{
Method = methodBase;
ProxyTarget = proxyTarget;
Target = target;
Arguments = arguments;
GenericArguments = methodBase?.GetGenericArguments() ?? [];
if (proxyMethod.ContainsGenericParameters && GenericArguments.Length > 0)
{
ProxyMethod = proxyMethod.MakeGenericMethod(GenericArguments);
}
else
{
ProxyMethod = proxyMethod;
}
Properties = [];
}
}