mscorlib(4.0.0.0) API with additions
DynamicILInfo.cs
2 using System.Security;
3 
5 {
7  [ComVisible(true)]
8  public class DynamicILInfo
9  {
10  private DynamicMethod m_method;
11 
12  private DynamicScope m_scope;
13 
14  private byte[] m_exceptions;
15 
16  private byte[] m_code;
17 
18  private byte[] m_localSignature;
19 
20  private int m_maxStackSize;
21 
22  private int m_methodSignature;
23 
24  internal byte[] LocalSignature
25  {
26  get
27  {
28  if (m_localSignature == null)
29  {
30  m_localSignature = SignatureHelper.GetLocalVarSigHelper().InternalGetSignatureArray();
31  }
32  return m_localSignature;
33  }
34  }
35 
36  internal byte[] Exceptions => m_exceptions;
37 
38  internal byte[] Code => m_code;
39 
40  internal int MaxStackSize => m_maxStackSize;
41 
44  public DynamicMethod DynamicMethod => m_method;
45 
46  internal DynamicScope DynamicScope => m_scope;
47 
48  internal DynamicILInfo(DynamicScope scope, DynamicMethod method, byte[] methodSignature)
49  {
50  m_method = method;
51  m_scope = scope;
52  m_methodSignature = m_scope.GetTokenFor(methodSignature);
53  m_exceptions = EmptyArray<byte>.Value;
54  m_code = EmptyArray<byte>.Value;
55  m_localSignature = EmptyArray<byte>.Value;
56  }
57 
58  [SecurityCritical]
59  internal void GetCallableMethod(RuntimeModule module, DynamicMethod dm)
60  {
61  dm.m_methodHandle = ModuleHandle.GetDynamicMethod(dm, module, m_method.Name, (byte[])m_scope[m_methodSignature], new DynamicResolver(this));
62  }
63 
67  public void SetCode(byte[] code, int maxStackSize)
68  {
69  m_code = ((code != null) ? ((byte[])code.Clone()) : EmptyArray<byte>.Value);
70  m_maxStackSize = maxStackSize;
71  }
72 
81  [SecurityCritical]
82  [CLSCompliant(false)]
83  public unsafe void SetCode(byte* code, int codeSize, int maxStackSize)
84  {
85  if (codeSize < 0)
86  {
87  throw new ArgumentOutOfRangeException("codeSize", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
88  }
89  if (codeSize > 0 && code == null)
90  {
91  throw new ArgumentNullException("code");
92  }
93  m_code = new byte[codeSize];
94  for (int i = 0; i < codeSize; i++)
95  {
96  m_code[i] = *code;
97  code++;
98  }
99  m_maxStackSize = maxStackSize;
100  }
101 
104  public void SetExceptions(byte[] exceptions)
105  {
106  m_exceptions = ((exceptions != null) ? ((byte[])exceptions.Clone()) : EmptyArray<byte>.Value);
107  }
108 
116  [SecurityCritical]
117  [CLSCompliant(false)]
118  public unsafe void SetExceptions(byte* exceptions, int exceptionsSize)
119  {
120  if (exceptionsSize < 0)
121  {
122  throw new ArgumentOutOfRangeException("exceptionsSize", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
123  }
124  if (exceptionsSize > 0 && exceptions == null)
125  {
126  throw new ArgumentNullException("exceptions");
127  }
128  m_exceptions = new byte[exceptionsSize];
129  for (int i = 0; i < exceptionsSize; i++)
130  {
131  m_exceptions[i] = *exceptions;
132  exceptions++;
133  }
134  }
135 
138  public void SetLocalSignature(byte[] localSignature)
139  {
140  m_localSignature = ((localSignature != null) ? ((byte[])localSignature.Clone()) : EmptyArray<byte>.Value);
141  }
142 
150  [SecurityCritical]
151  [CLSCompliant(false)]
152  public unsafe void SetLocalSignature(byte* localSignature, int signatureSize)
153  {
154  if (signatureSize < 0)
155  {
156  throw new ArgumentOutOfRangeException("signatureSize", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
157  }
158  if (signatureSize > 0 && localSignature == null)
159  {
160  throw new ArgumentNullException("localSignature");
161  }
162  m_localSignature = new byte[signatureSize];
163  for (int i = 0; i < signatureSize; i++)
164  {
165  m_localSignature[i] = *localSignature;
166  localSignature++;
167  }
168  }
169 
173  [SecuritySafeCritical]
174  public int GetTokenFor(RuntimeMethodHandle method)
175  {
176  return DynamicScope.GetTokenFor(method);
177  }
178 
182  public int GetTokenFor(DynamicMethod method)
183  {
184  return DynamicScope.GetTokenFor(method);
185  }
186 
191  public int GetTokenFor(RuntimeMethodHandle method, RuntimeTypeHandle contextType)
192  {
193  return DynamicScope.GetTokenFor(method, contextType);
194  }
195 
199  public int GetTokenFor(RuntimeFieldHandle field)
200  {
201  return DynamicScope.GetTokenFor(field);
202  }
203 
208  public int GetTokenFor(RuntimeFieldHandle field, RuntimeTypeHandle contextType)
209  {
210  return DynamicScope.GetTokenFor(field, contextType);
211  }
212 
217  {
218  return DynamicScope.GetTokenFor(type);
219  }
220 
224  public int GetTokenFor(string literal)
225  {
226  return DynamicScope.GetTokenFor(literal);
227  }
228 
232  public int GetTokenFor(byte[] signature)
233  {
234  return DynamicScope.GetTokenFor(signature);
235  }
236  }
237 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Defines and represents a dynamic method that can be compiled, executed, and discarded....
int GetTokenFor(RuntimeFieldHandle field, RuntimeTypeHandle contextType)
Gets a token, valid in the scope of the current T:System.Reflection.Emit.DynamicILInfo,...
Definition: __Canon.cs:3
Represents a field using an internal metadata token.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
Represents a runtime handle for a module.
Definition: ModuleHandle.cs:12
int GetTokenFor(RuntimeMethodHandle method)
Gets a token, valid in the scope of the current T:System.Reflection.Emit.DynamicILInfo,...
Represents a type using an internal metadata token.
Provides methods for building signatures.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
T:System.RuntimeMethodHandle is a handle to the internal metadata representation of a method.
override string Name
Gets the name of the dynamic method.
void SetCode(byte[] code, int maxStackSize)
Sets the code body of the associated dynamic method.
void SetExceptions(byte[] exceptions)
Sets the exception metadata for the associated dynamic method.
unsafe void SetLocalSignature(byte *localSignature, int signatureSize)
Sets the local variable signature that describes the layout of local variables for the associated dyn...
static SignatureHelper GetLocalVarSigHelper()
Returns a signature helper for a local variable.
int GetTokenFor(DynamicMethod method)
Gets a token, valid in the scope of the current T:System.Reflection.Emit.DynamicILInfo,...
int GetTokenFor(string literal)
Gets a token, valid in the scope of the current T:System.Reflection.Emit.DynamicILInfo,...
int GetTokenFor(RuntimeMethodHandle method, RuntimeTypeHandle contextType)
Gets a token, valid in the scope of the current T:System.Reflection.Emit.DynamicILInfo,...
unsafe void SetExceptions(byte *exceptions, int exceptionsSize)
Sets the exception metadata for the associated dynamic method.
Provides support for alternative ways to generate the Microsoft intermediate language (MSIL) and meta...
Definition: DynamicILInfo.cs:8
void SetLocalSignature(byte[] localSignature)
Sets the local variable signature that describes the layout of local variables for the associated dyn...
int GetTokenFor(byte[] signature)
Gets a token, valid in the scope of the current T:System.Reflection.Emit.DynamicILInfo,...
unsafe void SetCode(byte *code, int codeSize, int maxStackSize)
Sets the code body of the associated dynamic method.
int GetTokenFor(RuntimeTypeHandle type)
Gets a token, valid in the scope of the current T:System.Reflection.Emit.DynamicILInfo,...
int GetTokenFor(RuntimeFieldHandle field)
Gets a token, valid in the scope of the current T:System.Reflection.Emit.DynamicILInfo,...