/
MethodBuilder.cs
91 lines (65 loc) · 3.61 KB
/
MethodBuilder.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// 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;
namespace System.Reflection.Emit
{
public abstract class MethodBuilder : MethodInfo
{
protected MethodBuilder()
{
}
public bool InitLocals
{
get => InitLocalsCore;
set { InitLocalsCore = value; }
}
protected abstract bool InitLocalsCore { get; set; }
public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] names)
{
ArgumentNullException.ThrowIfNull(names);
if (names.Length == 0)
throw new ArgumentException(SR.Arg_EmptyArray, nameof(names));
return DefineGenericParametersCore(names);
}
protected abstract GenericTypeParameterBuilder[] DefineGenericParametersCore(params string[] names);
public ParameterBuilder DefineParameter(int position, ParameterAttributes attributes, string? strParamName)
{
ArgumentOutOfRangeException.ThrowIfNegative(position);
return DefineParameterCore(position, attributes, strParamName);
}
protected abstract ParameterBuilder DefineParameterCore(int position, ParameterAttributes attributes, string? strParamName);
public ILGenerator GetILGenerator()
=> GetILGenerator(64);
public ILGenerator GetILGenerator(int size)
=> GetILGeneratorCore(size);
protected abstract ILGenerator GetILGeneratorCore(int size);
public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
{
ArgumentNullException.ThrowIfNull(con);
ArgumentNullException.ThrowIfNull(binaryAttribute);
SetCustomAttributeCore(con, binaryAttribute);
}
internal void SetCustomAttribute(ConstructorInfo con, ReadOnlySpan<byte> binaryAttribute)
{
SetCustomAttributeCore(con, binaryAttribute);
}
protected abstract void SetCustomAttributeCore(ConstructorInfo con, ReadOnlySpan<byte> binaryAttribute);
public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
{
ArgumentNullException.ThrowIfNull(customBuilder);
SetCustomAttributeCore(customBuilder.Ctor, customBuilder.Data);
}
public void SetImplementationFlags(MethodImplAttributes attributes) => SetImplementationFlagsCore(attributes);
protected abstract void SetImplementationFlagsCore(MethodImplAttributes attributes);
public void SetParameters(params Type[] parameterTypes)
=> SetSignature(null, null, null, parameterTypes, null, null);
public void SetReturnType(Type? returnType)
=> SetSignature(returnType, null, null, null, null, null);
public void SetSignature(Type? returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers,
Type[]? parameterTypes, Type[][]? parameterTypeRequiredCustomModifiers, Type[][]? parameterTypeOptionalCustomModifiers)
=> SetSignatureCore(returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers,
parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers);
protected abstract void SetSignatureCore(Type? returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers,
Type[]? parameterTypes, Type[][]? parameterTypeRequiredCustomModifiers, Type[][]? parameterTypeOptionalCustomModifiers);
}
}