/
MethodBase.CoreCLR.cs
71 lines (57 loc) · 2.55 KB
/
MethodBase.CoreCLR.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
70
71
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics.CodeAnalysis;
using System.Threading;
namespace System.Reflection
{
public abstract partial class MethodBase : MemberInfo
{
#region Static Members
public static MethodBase? GetMethodFromHandle(RuntimeMethodHandle handle)
{
if (handle.IsNullHandle())
throw new ArgumentException(SR.Argument_InvalidHandle);
MethodBase? m = RuntimeType.GetMethodBase(handle.GetMethodInfo());
Type? declaringType = m?.DeclaringType;
if (declaringType != null && declaringType.IsGenericType)
throw new ArgumentException(SR.Format(
SR.Argument_MethodDeclaringTypeGeneric,
m, declaringType.GetGenericTypeDefinition()));
return m;
}
public static MethodBase? GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType)
{
if (handle.IsNullHandle())
throw new ArgumentException(SR.Argument_InvalidHandle);
return RuntimeType.GetMethodBase(declaringType.GetRuntimeType(), handle.GetMethodInfo());
}
[RequiresUnreferencedCode("Metadata for the method might be incomplete or removed")]
[System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
public static MethodBase? GetCurrentMethod()
{
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
return RuntimeMethodInfo.InternalGetCurrentMethod(ref stackMark);
}
#endregion
#region Internal Members
// used by EE
private IntPtr GetMethodDesc() { return MethodHandle.Value; }
internal virtual ParameterInfo[] GetParametersNoCopy() { return GetParameters(); }
#endregion
#region Internal Methods
// helper method to construct the string representation of the parameter list
internal virtual Type[] GetParameterTypes()
{
ParameterInfo[] paramInfo = GetParametersNoCopy();
if (paramInfo.Length == 0)
{
return Type.EmptyTypes;
}
Type[] parameterTypes = new Type[paramInfo.Length];
for (int i = 0; i < paramInfo.Length; i++)
parameterTypes[i] = paramInfo[i].ParameterType;
return parameterTypes;
}
#endregion
}
}