mscorlib(4.0.0.0) API with additions
ILGenerator.cs
2 using System.IO;
4 using System.Security;
5 
7 {
9  [ClassInterface(ClassInterfaceType.None)]
10  [ComDefaultInterface(typeof(_ILGenerator))]
11  [ComVisible(true)]
12  public class ILGenerator : _ILGenerator
13  {
14  private const int defaultSize = 16;
15 
16  private const int DefaultFixupArraySize = 8;
17 
18  private const int DefaultLabelArraySize = 4;
19 
20  private const int DefaultExceptionArraySize = 2;
21 
22  private int m_length;
23 
24  private byte[] m_ILStream;
25 
26  private int[] m_labelList;
27 
28  private int m_labelCount;
29 
30  private __FixupData[] m_fixupData;
31 
32  private int m_fixupCount;
33 
34  private int[] m_RelocFixupList;
35 
36  private int m_RelocFixupCount;
37 
38  private int m_exceptionCount;
39 
40  private int m_currExcStackCount;
41 
42  private __ExceptionInfo[] m_exceptions;
43 
44  private __ExceptionInfo[] m_currExcStack;
45 
46  internal ScopeTree m_ScopeTree;
47 
48  internal LineNumberInfo m_LineNumberInfo;
49 
50  internal MethodInfo m_methodBuilder;
51 
52  internal int m_localCount;
53 
54  internal SignatureHelper m_localSignature;
55 
56  private int m_maxStackSize;
57 
58  private int m_maxMidStack;
59 
60  private int m_maxMidStackCur;
61 
62  internal int CurrExcStackCount => m_currExcStackCount;
63 
64  internal __ExceptionInfo[] CurrExcStack => m_currExcStack;
65 
68  public virtual int ILOffset => m_length;
69 
70  internal static int[] EnlargeArray(int[] incoming)
71  {
72  int[] array = new int[incoming.Length * 2];
73  Array.Copy(incoming, array, incoming.Length);
74  return array;
75  }
76 
77  private static byte[] EnlargeArray(byte[] incoming)
78  {
79  byte[] array = new byte[incoming.Length * 2];
80  Array.Copy(incoming, array, incoming.Length);
81  return array;
82  }
83 
84  private static byte[] EnlargeArray(byte[] incoming, int requiredSize)
85  {
86  byte[] array = new byte[requiredSize];
87  Array.Copy(incoming, array, incoming.Length);
88  return array;
89  }
90 
91  private static __FixupData[] EnlargeArray(__FixupData[] incoming)
92  {
93  __FixupData[] array = new __FixupData[incoming.Length * 2];
94  Array.Copy(incoming, array, incoming.Length);
95  return array;
96  }
97 
98  private static __ExceptionInfo[] EnlargeArray(__ExceptionInfo[] incoming)
99  {
100  __ExceptionInfo[] array = new __ExceptionInfo[incoming.Length * 2];
101  Array.Copy(incoming, array, incoming.Length);
102  return array;
103  }
104 
105  internal ILGenerator(MethodInfo methodBuilder)
106  : this(methodBuilder, 64)
107  {
108  }
109 
110  internal ILGenerator(MethodInfo methodBuilder, int size)
111  {
112  if (size < 16)
113  {
114  m_ILStream = new byte[16];
115  }
116  else
117  {
118  m_ILStream = new byte[size];
119  }
120  m_length = 0;
121  m_labelCount = 0;
122  m_fixupCount = 0;
123  m_labelList = null;
124  m_fixupData = null;
125  m_exceptions = null;
126  m_exceptionCount = 0;
127  m_currExcStack = null;
128  m_currExcStackCount = 0;
129  m_RelocFixupList = null;
130  m_RelocFixupCount = 0;
131  m_ScopeTree = new ScopeTree();
132  m_LineNumberInfo = new LineNumberInfo();
133  m_methodBuilder = methodBuilder;
134  m_localCount = 0;
135  MethodBuilder methodBuilder2 = m_methodBuilder as MethodBuilder;
136  if (methodBuilder2 == null)
137  {
138  m_localSignature = SignatureHelper.GetLocalVarSigHelper(null);
139  }
140  else
141  {
142  m_localSignature = SignatureHelper.GetLocalVarSigHelper(methodBuilder2.GetTypeBuilder().Module);
143  }
144  }
145 
146  internal virtual void RecordTokenFixup()
147  {
148  if (m_RelocFixupList == null)
149  {
150  m_RelocFixupList = new int[8];
151  }
152  else if (m_RelocFixupList.Length <= m_RelocFixupCount)
153  {
154  m_RelocFixupList = EnlargeArray(m_RelocFixupList);
155  }
156  m_RelocFixupList[m_RelocFixupCount++] = m_length;
157  }
158 
159  internal void InternalEmit(OpCode opcode)
160  {
161  if (opcode.Size != 1)
162  {
163  m_ILStream[m_length++] = (byte)(opcode.Value >> 8);
164  }
165  m_ILStream[m_length++] = (byte)opcode.Value;
166  UpdateStackSize(opcode, opcode.StackChange());
167  }
168 
169  internal void UpdateStackSize(OpCode opcode, int stackchange)
170  {
171  m_maxMidStackCur += stackchange;
172  if (m_maxMidStackCur > m_maxMidStack)
173  {
174  m_maxMidStack = m_maxMidStackCur;
175  }
176  else if (m_maxMidStackCur < 0)
177  {
178  m_maxMidStackCur = 0;
179  }
180  if (opcode.EndsUncondJmpBlk())
181  {
182  m_maxStackSize += m_maxMidStack;
183  m_maxMidStack = 0;
184  m_maxMidStackCur = 0;
185  }
186  }
187 
188  [SecurityCritical]
189  private int GetMethodToken(MethodBase method, Type[] optionalParameterTypes, bool useMethodDef)
190  {
191  return ((ModuleBuilder)m_methodBuilder.Module).GetMethodTokenInternal(method, optionalParameterTypes, useMethodDef);
192  }
193 
194  [SecurityCritical]
195  internal virtual SignatureHelper GetMemberRefSignature(CallingConventions call, Type returnType, Type[] parameterTypes, Type[] optionalParameterTypes)
196  {
197  return GetMemberRefSignature(call, returnType, parameterTypes, optionalParameterTypes, 0);
198  }
199 
200  [SecurityCritical]
201  private SignatureHelper GetMemberRefSignature(CallingConventions call, Type returnType, Type[] parameterTypes, Type[] optionalParameterTypes, int cGenericParameters)
202  {
203  return ((ModuleBuilder)m_methodBuilder.Module).GetMemberRefSignature(call, returnType, parameterTypes, optionalParameterTypes, cGenericParameters);
204  }
205 
206  internal byte[] BakeByteArray()
207  {
208  if (m_currExcStackCount != 0)
209  {
210  throw new ArgumentException(Environment.GetResourceString("Argument_UnclosedExceptionBlock"));
211  }
212  if (m_length == 0)
213  {
214  return null;
215  }
216  int length = m_length;
217  byte[] array = new byte[length];
218  Array.Copy(m_ILStream, array, length);
219  for (int i = 0; i < m_fixupCount; i++)
220  {
221  int num = GetLabelPos(m_fixupData[i].m_fixupLabel) - (m_fixupData[i].m_fixupPos + m_fixupData[i].m_fixupInstSize);
222  if (m_fixupData[i].m_fixupInstSize == 1)
223  {
224  if (num < -128 || num > 127)
225  {
226  throw new NotSupportedException(Environment.GetResourceString("NotSupported_IllegalOneByteBranch", m_fixupData[i].m_fixupPos, num));
227  }
228  if (num < 0)
229  {
230  array[m_fixupData[i].m_fixupPos] = (byte)(256 + num);
231  }
232  else
233  {
234  array[m_fixupData[i].m_fixupPos] = (byte)num;
235  }
236  }
237  else
238  {
239  PutInteger4InArray(num, m_fixupData[i].m_fixupPos, array);
240  }
241  }
242  return array;
243  }
244 
245  internal __ExceptionInfo[] GetExceptions()
246  {
247  if (m_currExcStackCount != 0)
248  {
249  throw new NotSupportedException(Environment.GetResourceString("Argument_UnclosedExceptionBlock"));
250  }
251  if (m_exceptionCount == 0)
252  {
253  return null;
254  }
255  __ExceptionInfo[] array = new __ExceptionInfo[m_exceptionCount];
256  Array.Copy(m_exceptions, array, m_exceptionCount);
257  SortExceptions(array);
258  return array;
259  }
260 
261  internal void EnsureCapacity(int size)
262  {
263  if (m_length + size >= m_ILStream.Length)
264  {
265  if (m_length + size >= 2 * m_ILStream.Length)
266  {
267  m_ILStream = EnlargeArray(m_ILStream, m_length + size);
268  }
269  else
270  {
271  m_ILStream = EnlargeArray(m_ILStream);
272  }
273  }
274  }
275 
276  internal void PutInteger4(int value)
277  {
278  m_length = PutInteger4InArray(value, m_length, m_ILStream);
279  }
280 
281  private static int PutInteger4InArray(int value, int startPos, byte[] array)
282  {
283  array[startPos++] = (byte)value;
284  array[startPos++] = (byte)(value >> 8);
285  array[startPos++] = (byte)(value >> 16);
286  array[startPos++] = (byte)(value >> 24);
287  return startPos;
288  }
289 
290  private int GetLabelPos(Label lbl)
291  {
292  int labelValue = lbl.GetLabelValue();
293  if (labelValue < 0 || labelValue >= m_labelCount)
294  {
295  throw new ArgumentException(Environment.GetResourceString("Argument_BadLabel"));
296  }
297  if (m_labelList[labelValue] < 0)
298  {
299  throw new ArgumentException(Environment.GetResourceString("Argument_BadLabelContent"));
300  }
301  return m_labelList[labelValue];
302  }
303 
304  private void AddFixup(Label lbl, int pos, int instSize)
305  {
306  if (m_fixupData == null)
307  {
308  m_fixupData = new __FixupData[8];
309  }
310  else if (m_fixupData.Length <= m_fixupCount)
311  {
312  m_fixupData = EnlargeArray(m_fixupData);
313  }
314  m_fixupData[m_fixupCount].m_fixupPos = pos;
315  m_fixupData[m_fixupCount].m_fixupLabel = lbl;
316  m_fixupData[m_fixupCount].m_fixupInstSize = instSize;
317  m_fixupCount++;
318  }
319 
320  internal int GetMaxStackSize()
321  {
322  return m_maxStackSize;
323  }
324 
325  private static void SortExceptions(__ExceptionInfo[] exceptions)
326  {
327  int num = exceptions.Length;
328  for (int i = 0; i < num; i++)
329  {
330  int num2 = i;
331  for (int j = i + 1; j < num; j++)
332  {
333  if (exceptions[num2].IsInner(exceptions[j]))
334  {
335  num2 = j;
336  }
337  }
338  __ExceptionInfo _ExceptionInfo = exceptions[i];
339  exceptions[i] = exceptions[num2];
340  exceptions[num2] = _ExceptionInfo;
341  }
342  }
343 
344  internal int[] GetTokenFixups()
345  {
346  if (m_RelocFixupCount == 0)
347  {
348  return null;
349  }
350  int[] array = new int[m_RelocFixupCount];
351  Array.Copy(m_RelocFixupList, array, m_RelocFixupCount);
352  return array;
353  }
354 
357  public virtual void Emit(OpCode opcode)
358  {
359  EnsureCapacity(3);
360  InternalEmit(opcode);
361  }
362 
366  public virtual void Emit(OpCode opcode, byte arg)
367  {
368  EnsureCapacity(4);
369  InternalEmit(opcode);
370  m_ILStream[m_length++] = arg;
371  }
372 
376  [CLSCompliant(false)]
377  public void Emit(OpCode opcode, sbyte arg)
378  {
379  EnsureCapacity(4);
380  InternalEmit(opcode);
381  if (arg < 0)
382  {
383  m_ILStream[m_length++] = (byte)(256 + arg);
384  }
385  else
386  {
387  m_ILStream[m_length++] = (byte)arg;
388  }
389  }
390 
394  public virtual void Emit(OpCode opcode, short arg)
395  {
396  EnsureCapacity(5);
397  InternalEmit(opcode);
398  m_ILStream[m_length++] = (byte)arg;
399  m_ILStream[m_length++] = (byte)(arg >> 8);
400  }
401 
405  public virtual void Emit(OpCode opcode, int arg)
406  {
407  EnsureCapacity(7);
408  InternalEmit(opcode);
409  PutInteger4(arg);
410  }
411 
419  [SecuritySafeCritical]
420  public virtual void Emit(OpCode opcode, MethodInfo meth)
421  {
422  if (meth == null)
423  {
424  throw new ArgumentNullException("meth");
425  }
426  if (opcode.Equals(OpCodes.Call) || opcode.Equals(OpCodes.Callvirt) || opcode.Equals(OpCodes.Newobj))
427  {
428  EmitCall(opcode, meth, null);
429  return;
430  }
431  int stackchange = 0;
432  bool useMethodDef = opcode.Equals(OpCodes.Ldtoken) || opcode.Equals(OpCodes.Ldftn) || opcode.Equals(OpCodes.Ldvirtftn);
433  int methodToken = GetMethodToken(meth, null, useMethodDef);
434  EnsureCapacity(7);
435  InternalEmit(opcode);
436  UpdateStackSize(opcode, stackchange);
437  RecordTokenFixup();
438  PutInteger4(methodToken);
439  }
440 
449  [SecuritySafeCritical]
450  public virtual void EmitCalli(OpCode opcode, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Type[] optionalParameterTypes)
451  {
452  int num = 0;
453  if (optionalParameterTypes != null && (callingConvention & CallingConventions.VarArgs) == (CallingConventions)0)
454  {
455  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotAVarArgCallingConvention"));
456  }
457  ModuleBuilder moduleBuilder = (ModuleBuilder)m_methodBuilder.Module;
458  SignatureHelper memberRefSignature = GetMemberRefSignature(callingConvention, returnType, parameterTypes, optionalParameterTypes);
459  EnsureCapacity(7);
460  Emit(OpCodes.Calli);
461  if (returnType != typeof(void))
462  {
463  num++;
464  }
465  if (parameterTypes != null)
466  {
467  num -= parameterTypes.Length;
468  }
469  if (optionalParameterTypes != null)
470  {
471  num -= optionalParameterTypes.Length;
472  }
473  if ((callingConvention & CallingConventions.HasThis) == CallingConventions.HasThis)
474  {
475  num--;
476  }
477  num--;
478  UpdateStackSize(OpCodes.Calli, num);
479  RecordTokenFixup();
480  PutInteger4(moduleBuilder.GetSignatureToken(memberRefSignature).Token);
481  }
482 
488  public virtual void EmitCalli(OpCode opcode, CallingConvention unmanagedCallConv, Type returnType, Type[] parameterTypes)
489  {
490  int num = 0;
491  int num2 = 0;
492  ModuleBuilder moduleBuilder = (ModuleBuilder)m_methodBuilder.Module;
493  if (parameterTypes != null)
494  {
495  num2 = parameterTypes.Length;
496  }
497  SignatureHelper methodSigHelper = SignatureHelper.GetMethodSigHelper(moduleBuilder, unmanagedCallConv, returnType);
498  if (parameterTypes != null)
499  {
500  for (int i = 0; i < num2; i++)
501  {
502  methodSigHelper.AddArgument(parameterTypes[i]);
503  }
504  }
505  if (returnType != typeof(void))
506  {
507  num++;
508  }
509  if (parameterTypes != null)
510  {
511  num -= num2;
512  }
513  num--;
514  UpdateStackSize(OpCodes.Calli, num);
515  EnsureCapacity(7);
516  Emit(OpCodes.Calli);
517  RecordTokenFixup();
518  PutInteger4(moduleBuilder.GetSignatureToken(methodSigHelper).Token);
519  }
520 
530  [SecuritySafeCritical]
531  public virtual void EmitCall(OpCode opcode, MethodInfo methodInfo, Type[] optionalParameterTypes)
532  {
533  if (methodInfo == null)
534  {
535  throw new ArgumentNullException("methodInfo");
536  }
537  if (!opcode.Equals(OpCodes.Call) && !opcode.Equals(OpCodes.Callvirt) && !opcode.Equals(OpCodes.Newobj))
538  {
539  throw new ArgumentException(Environment.GetResourceString("Argument_NotMethodCallOpcode"), "opcode");
540  }
541  int num = 0;
542  int methodToken = GetMethodToken(methodInfo, optionalParameterTypes, useMethodDef: false);
543  EnsureCapacity(7);
544  InternalEmit(opcode);
545  if (methodInfo.ReturnType != typeof(void))
546  {
547  num++;
548  }
549  Type[] parameterTypes = methodInfo.GetParameterTypes();
550  if (parameterTypes != null)
551  {
552  num -= parameterTypes.Length;
553  }
554  if (!(methodInfo is SymbolMethod) && !methodInfo.IsStatic && !opcode.Equals(OpCodes.Newobj))
555  {
556  num--;
557  }
558  if (optionalParameterTypes != null)
559  {
560  num -= optionalParameterTypes.Length;
561  }
562  UpdateStackSize(opcode, num);
563  RecordTokenFixup();
564  PutInteger4(methodToken);
565  }
566 
572  public virtual void Emit(OpCode opcode, SignatureHelper signature)
573  {
574  if (signature == null)
575  {
576  throw new ArgumentNullException("signature");
577  }
578  int num = 0;
579  ModuleBuilder moduleBuilder = (ModuleBuilder)m_methodBuilder.Module;
580  int token = moduleBuilder.GetSignatureToken(signature).Token;
581  EnsureCapacity(7);
582  InternalEmit(opcode);
583  if (opcode.StackBehaviourPop == StackBehaviour.Varpop)
584  {
585  num -= signature.ArgumentCount;
586  num--;
587  UpdateStackSize(opcode, num);
588  }
589  RecordTokenFixup();
590  PutInteger4(token);
591  }
592 
598  [SecuritySafeCritical]
599  [ComVisible(true)]
600  public virtual void Emit(OpCode opcode, ConstructorInfo con)
601  {
602  if (con == null)
603  {
604  throw new ArgumentNullException("con");
605  }
606  int num = 0;
607  int methodToken = GetMethodToken(con, null, useMethodDef: true);
608  EnsureCapacity(7);
609  InternalEmit(opcode);
610  if (opcode.StackBehaviourPush == StackBehaviour.Varpush)
611  {
612  num++;
613  }
614  if (opcode.StackBehaviourPop == StackBehaviour.Varpop)
615  {
616  Type[] parameterTypes = con.GetParameterTypes();
617  if (parameterTypes != null)
618  {
619  num -= parameterTypes.Length;
620  }
621  }
622  UpdateStackSize(opcode, num);
623  RecordTokenFixup();
624  PutInteger4(methodToken);
625  }
626 
632  [SecuritySafeCritical]
633  public virtual void Emit(OpCode opcode, Type cls)
634  {
635  int num = 0;
636  ModuleBuilder moduleBuilder = (ModuleBuilder)m_methodBuilder.Module;
637  num = ((!(opcode == OpCodes.Ldtoken) || !(cls != null) || !cls.IsGenericTypeDefinition) ? moduleBuilder.GetTypeTokenInternal(cls).Token : moduleBuilder.GetTypeToken(cls).Token);
638  EnsureCapacity(7);
639  InternalEmit(opcode);
640  RecordTokenFixup();
641  PutInteger4(num);
642  }
643 
647  public virtual void Emit(OpCode opcode, long arg)
648  {
649  EnsureCapacity(11);
650  InternalEmit(opcode);
651  m_ILStream[m_length++] = (byte)arg;
652  m_ILStream[m_length++] = (byte)(arg >> 8);
653  m_ILStream[m_length++] = (byte)(arg >> 16);
654  m_ILStream[m_length++] = (byte)(arg >> 24);
655  m_ILStream[m_length++] = (byte)(arg >> 32);
656  m_ILStream[m_length++] = (byte)(arg >> 40);
657  m_ILStream[m_length++] = (byte)(arg >> 48);
658  m_ILStream[m_length++] = (byte)(arg >> 56);
659  }
660 
664  [SecuritySafeCritical]
665  public unsafe virtual void Emit(OpCode opcode, float arg)
666  {
667  EnsureCapacity(7);
668  InternalEmit(opcode);
669  uint num = *(uint*)(&arg);
670  m_ILStream[m_length++] = (byte)num;
671  m_ILStream[m_length++] = (byte)(num >> 8);
672  m_ILStream[m_length++] = (byte)(num >> 16);
673  m_ILStream[m_length++] = (byte)(num >> 24);
674  }
675 
679  [SecuritySafeCritical]
680  public unsafe virtual void Emit(OpCode opcode, double arg)
681  {
682  EnsureCapacity(11);
683  InternalEmit(opcode);
684  ulong num = (ulong)(*(long*)(&arg));
685  m_ILStream[m_length++] = (byte)num;
686  m_ILStream[m_length++] = (byte)(num >> 8);
687  m_ILStream[m_length++] = (byte)(num >> 16);
688  m_ILStream[m_length++] = (byte)(num >> 24);
689  m_ILStream[m_length++] = (byte)(num >> 32);
690  m_ILStream[m_length++] = (byte)(num >> 40);
691  m_ILStream[m_length++] = (byte)(num >> 48);
692  m_ILStream[m_length++] = (byte)(num >> 56);
693  }
694 
698  public virtual void Emit(OpCode opcode, Label label)
699  {
700  int labelValue = label.GetLabelValue();
701  EnsureCapacity(7);
702  InternalEmit(opcode);
703  if (OpCodes.TakesSingleByteArgument(opcode))
704  {
705  AddFixup(label, m_length, 1);
706  m_length++;
707  }
708  else
709  {
710  AddFixup(label, m_length, 4);
711  m_length += 4;
712  }
713  }
714 
720  public virtual void Emit(OpCode opcode, Label[] labels)
721  {
722  if (labels == null)
723  {
724  throw new ArgumentNullException("labels");
725  }
726  int num = labels.Length;
727  EnsureCapacity(num * 4 + 7);
728  InternalEmit(opcode);
729  PutInteger4(num);
730  int num2 = num * 4;
731  int num3 = 0;
732  while (num2 > 0)
733  {
734  AddFixup(labels[num3], m_length, num2);
735  m_length += 4;
736  num2 -= 4;
737  num3++;
738  }
739  }
740 
744  public virtual void Emit(OpCode opcode, FieldInfo field)
745  {
746  ModuleBuilder moduleBuilder = (ModuleBuilder)m_methodBuilder.Module;
747  int token = moduleBuilder.GetFieldToken(field).Token;
748  EnsureCapacity(7);
749  InternalEmit(opcode);
750  RecordTokenFixup();
751  PutInteger4(token);
752  }
753 
757  public virtual void Emit(OpCode opcode, string str)
758  {
759  ModuleBuilder moduleBuilder = (ModuleBuilder)m_methodBuilder.Module;
760  int token = moduleBuilder.GetStringConstant(str).Token;
761  EnsureCapacity(7);
762  InternalEmit(opcode);
763  PutInteger4(token);
764  }
765 
776  public virtual void Emit(OpCode opcode, LocalBuilder local)
777  {
778  if (local == null)
779  {
780  throw new ArgumentNullException("local");
781  }
782  int localIndex = local.GetLocalIndex();
783  if (local.GetMethodBuilder() != m_methodBuilder)
784  {
785  throw new ArgumentException(Environment.GetResourceString("Argument_UnmatchedMethodForLocal"), "local");
786  }
787  if (opcode.Equals(OpCodes.Ldloc))
788  {
789  switch (localIndex)
790  {
791  case 0:
792  opcode = OpCodes.Ldloc_0;
793  break;
794  case 1:
795  opcode = OpCodes.Ldloc_1;
796  break;
797  case 2:
798  opcode = OpCodes.Ldloc_2;
799  break;
800  case 3:
801  opcode = OpCodes.Ldloc_3;
802  break;
803  default:
804  if (localIndex <= 255)
805  {
806  opcode = OpCodes.Ldloc_S;
807  }
808  break;
809  }
810  }
811  else if (opcode.Equals(OpCodes.Stloc))
812  {
813  switch (localIndex)
814  {
815  case 0:
816  opcode = OpCodes.Stloc_0;
817  break;
818  case 1:
819  opcode = OpCodes.Stloc_1;
820  break;
821  case 2:
822  opcode = OpCodes.Stloc_2;
823  break;
824  case 3:
825  opcode = OpCodes.Stloc_3;
826  break;
827  default:
828  if (localIndex <= 255)
829  {
830  opcode = OpCodes.Stloc_S;
831  }
832  break;
833  }
834  }
835  else if (opcode.Equals(OpCodes.Ldloca) && localIndex <= 255)
836  {
837  opcode = OpCodes.Ldloca_S;
838  }
839  EnsureCapacity(7);
840  InternalEmit(opcode);
841  if (opcode.OperandType == OperandType.InlineNone)
842  {
843  return;
844  }
845  if (!OpCodes.TakesSingleByteArgument(opcode))
846  {
847  m_ILStream[m_length++] = (byte)localIndex;
848  m_ILStream[m_length++] = (byte)(localIndex >> 8);
849  return;
850  }
851  if (localIndex > 255)
852  {
853  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadInstructionOrIndexOutOfBound"));
854  }
855  m_ILStream[m_length++] = (byte)localIndex;
856  }
857 
860  public virtual Label BeginExceptionBlock()
861  {
862  if (m_exceptions == null)
863  {
864  m_exceptions = new __ExceptionInfo[2];
865  }
866  if (m_currExcStack == null)
867  {
868  m_currExcStack = new __ExceptionInfo[2];
869  }
870  if (m_exceptionCount >= m_exceptions.Length)
871  {
872  m_exceptions = EnlargeArray(m_exceptions);
873  }
874  if (m_currExcStackCount >= m_currExcStack.Length)
875  {
876  m_currExcStack = EnlargeArray(m_currExcStack);
877  }
878  Label label = DefineLabel();
879  __ExceptionInfo _ExceptionInfo = new __ExceptionInfo(m_length, label);
880  m_exceptions[m_exceptionCount++] = _ExceptionInfo;
881  m_currExcStack[m_currExcStackCount++] = _ExceptionInfo;
882  return label;
883  }
884 
888  public virtual void EndExceptionBlock()
889  {
890  if (m_currExcStackCount == 0)
891  {
892  throw new NotSupportedException(Environment.GetResourceString("Argument_NotInExceptionBlock"));
893  }
894  __ExceptionInfo _ExceptionInfo = m_currExcStack[m_currExcStackCount - 1];
895  m_currExcStack[m_currExcStackCount - 1] = null;
896  m_currExcStackCount--;
897  Label endLabel = _ExceptionInfo.GetEndLabel();
898  switch (_ExceptionInfo.GetCurrentState())
899  {
900  case 0:
901  case 1:
902  throw new InvalidOperationException(Environment.GetResourceString("Argument_BadExceptionCodeGen"));
903  case 2:
904  Emit(OpCodes.Leave, endLabel);
905  break;
906  case 3:
907  case 4:
909  break;
910  }
911  if (m_labelList[endLabel.GetLabelValue()] == -1)
912  {
913  MarkLabel(endLabel);
914  }
915  else
916  {
917  MarkLabel(_ExceptionInfo.GetFinallyEndLabel());
918  }
919  _ExceptionInfo.Done(m_length);
920  }
921 
924  public virtual void BeginExceptFilterBlock()
925  {
926  if (m_currExcStackCount == 0)
927  {
928  throw new NotSupportedException(Environment.GetResourceString("Argument_NotInExceptionBlock"));
929  }
930  __ExceptionInfo _ExceptionInfo = m_currExcStack[m_currExcStackCount - 1];
931  Label endLabel = _ExceptionInfo.GetEndLabel();
932  Emit(OpCodes.Leave, endLabel);
933  _ExceptionInfo.MarkFilterAddr(m_length);
934  }
935 
942  public virtual void BeginCatchBlock(Type exceptionType)
943  {
944  if (m_currExcStackCount == 0)
945  {
946  throw new NotSupportedException(Environment.GetResourceString("Argument_NotInExceptionBlock"));
947  }
948  __ExceptionInfo _ExceptionInfo = m_currExcStack[m_currExcStackCount - 1];
949  if (_ExceptionInfo.GetCurrentState() == 1)
950  {
951  if (exceptionType != null)
952  {
953  throw new ArgumentException(Environment.GetResourceString("Argument_ShouldNotSpecifyExceptionType"));
954  }
956  }
957  else
958  {
959  if (exceptionType == null)
960  {
961  throw new ArgumentNullException("exceptionType");
962  }
963  Label endLabel = _ExceptionInfo.GetEndLabel();
964  Emit(OpCodes.Leave, endLabel);
965  }
966  _ExceptionInfo.MarkCatchAddr(m_length, exceptionType);
967  }
968 
971  public virtual void BeginFaultBlock()
972  {
973  if (m_currExcStackCount == 0)
974  {
975  throw new NotSupportedException(Environment.GetResourceString("Argument_NotInExceptionBlock"));
976  }
977  __ExceptionInfo _ExceptionInfo = m_currExcStack[m_currExcStackCount - 1];
978  Label endLabel = _ExceptionInfo.GetEndLabel();
979  Emit(OpCodes.Leave, endLabel);
980  _ExceptionInfo.MarkFaultAddr(m_length);
981  }
982 
985  public virtual void BeginFinallyBlock()
986  {
987  if (m_currExcStackCount == 0)
988  {
989  throw new NotSupportedException(Environment.GetResourceString("Argument_NotInExceptionBlock"));
990  }
991  __ExceptionInfo _ExceptionInfo = m_currExcStack[m_currExcStackCount - 1];
992  int currentState = _ExceptionInfo.GetCurrentState();
993  Label endLabel = _ExceptionInfo.GetEndLabel();
994  int num = 0;
995  if (currentState != 0)
996  {
997  Emit(OpCodes.Leave, endLabel);
998  num = m_length;
999  }
1000  MarkLabel(endLabel);
1001  Label label = DefineLabel();
1002  _ExceptionInfo.SetFinallyEndLabel(label);
1003  Emit(OpCodes.Leave, label);
1004  if (num == 0)
1005  {
1006  num = m_length;
1007  }
1008  _ExceptionInfo.MarkFinallyAddr(m_length, num);
1009  }
1010 
1013  public virtual Label DefineLabel()
1014  {
1015  if (m_labelList == null)
1016  {
1017  m_labelList = new int[4];
1018  }
1019  if (m_labelCount >= m_labelList.Length)
1020  {
1021  m_labelList = EnlargeArray(m_labelList);
1022  }
1023  m_labelList[m_labelCount] = -1;
1024  return new Label(m_labelCount++);
1025  }
1026 
1031  public virtual void MarkLabel(Label loc)
1032  {
1033  int labelValue = loc.GetLabelValue();
1034  if (labelValue < 0 || labelValue >= m_labelList.Length)
1035  {
1036  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidLabel"));
1037  }
1038  if (m_labelList[labelValue] != -1)
1039  {
1040  throw new ArgumentException(Environment.GetResourceString("Argument_RedefinedLabel"));
1041  }
1042  m_labelList[labelValue] = m_length;
1043  }
1044 
1051  public virtual void ThrowException(Type excType)
1052  {
1053  if (excType == null)
1054  {
1055  throw new ArgumentNullException("excType");
1056  }
1057  if (!excType.IsSubclassOf(typeof(Exception)) && excType != typeof(Exception))
1058  {
1059  throw new ArgumentException(Environment.GetResourceString("Argument_NotExceptionType"));
1060  }
1061  ConstructorInfo constructor = excType.GetConstructor(Type.EmptyTypes);
1062  if (constructor == null)
1063  {
1064  throw new ArgumentException(Environment.GetResourceString("Argument_MissingDefaultConstructor"));
1065  }
1066  Emit(OpCodes.Newobj, constructor);
1067  Emit(OpCodes.Throw);
1068  }
1069 
1072  public virtual void EmitWriteLine(string value)
1073  {
1074  Emit(OpCodes.Ldstr, value);
1075  Type[] types = new Type[1]
1076  {
1077  typeof(string)
1078  };
1079  MethodInfo method = typeof(Console).GetMethod("WriteLine", types);
1080  Emit(OpCodes.Call, method);
1081  }
1082 
1088  public virtual void EmitWriteLine(LocalBuilder localBuilder)
1089  {
1090  if (m_methodBuilder == null)
1091  {
1092  throw new ArgumentException(Environment.GetResourceString("InvalidOperation_BadILGeneratorUsage"));
1093  }
1094  MethodInfo method = typeof(Console).GetMethod("get_Out");
1095  Emit(OpCodes.Call, method);
1096  Emit(OpCodes.Ldloc, localBuilder);
1097  Type[] array = new Type[1];
1098  object localType = localBuilder.LocalType;
1099  if (localType is TypeBuilder || localType is EnumBuilder)
1100  {
1101  throw new ArgumentException(Environment.GetResourceString("NotSupported_OutputStreamUsingTypeBuilder"));
1102  }
1103  array[0] = (Type)localType;
1104  MethodInfo method2 = typeof(TextWriter).GetMethod("WriteLine", array);
1105  if (method2 == null)
1106  {
1107  throw new ArgumentException(Environment.GetResourceString("Argument_EmitWriteLineType"), "localBuilder");
1108  }
1109  Emit(OpCodes.Callvirt, method2);
1110  }
1111 
1118  public virtual void EmitWriteLine(FieldInfo fld)
1119  {
1120  if (fld == null)
1121  {
1122  throw new ArgumentNullException("fld");
1123  }
1124  MethodInfo method = typeof(Console).GetMethod("get_Out");
1125  Emit(OpCodes.Call, method);
1126  if ((fld.Attributes & FieldAttributes.Static) != 0)
1127  {
1128  Emit(OpCodes.Ldsfld, fld);
1129  }
1130  else
1131  {
1132  Emit(OpCodes.Ldarg, (short)0);
1133  Emit(OpCodes.Ldfld, fld);
1134  }
1135  Type[] array = new Type[1];
1136  object fieldType = fld.FieldType;
1137  if (fieldType is TypeBuilder || fieldType is EnumBuilder)
1138  {
1139  throw new NotSupportedException(Environment.GetResourceString("NotSupported_OutputStreamUsingTypeBuilder"));
1140  }
1141  array[0] = (Type)fieldType;
1142  MethodInfo method2 = typeof(TextWriter).GetMethod("WriteLine", array);
1143  if (method2 == null)
1144  {
1145  throw new ArgumentException(Environment.GetResourceString("Argument_EmitWriteLineType"), "fld");
1146  }
1147  Emit(OpCodes.Callvirt, method2);
1148  }
1149 
1156  public virtual LocalBuilder DeclareLocal(Type localType)
1157  {
1158  return DeclareLocal(localType, pinned: false);
1159  }
1160 
1170  public virtual LocalBuilder DeclareLocal(Type localType, bool pinned)
1171  {
1172  MethodBuilder methodBuilder = m_methodBuilder as MethodBuilder;
1173  if (methodBuilder == null)
1174  {
1175  throw new NotSupportedException();
1176  }
1177  if (methodBuilder.IsTypeCreated())
1178  {
1179  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_TypeHasBeenCreated"));
1180  }
1181  if (localType == null)
1182  {
1183  throw new ArgumentNullException("localType");
1184  }
1185  if (methodBuilder.m_bIsBaked)
1186  {
1187  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_MethodBaked"));
1188  }
1189  m_localSignature.AddArgument(localType, pinned);
1190  LocalBuilder result = new LocalBuilder(m_localCount, localType, methodBuilder, pinned);
1191  m_localCount++;
1192  return result;
1193  }
1194 
1201  public virtual void UsingNamespace(string usingNamespace)
1202  {
1203  if (usingNamespace == null)
1204  {
1205  throw new ArgumentNullException("usingNamespace");
1206  }
1207  if (usingNamespace.Length == 0)
1208  {
1209  throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "usingNamespace");
1210  }
1211  MethodBuilder methodBuilder = m_methodBuilder as MethodBuilder;
1212  if (methodBuilder == null)
1213  {
1214  throw new NotSupportedException();
1215  }
1216  int currentActiveScopeIndex = methodBuilder.GetILGenerator().m_ScopeTree.GetCurrentActiveScopeIndex();
1217  if (currentActiveScopeIndex == -1)
1218  {
1219  methodBuilder.m_localSymInfo.AddUsingNamespace(usingNamespace);
1220  }
1221  else
1222  {
1223  m_ScopeTree.AddUsingNamespaceToCurrentScope(usingNamespace);
1224  }
1225  }
1226 
1236  public virtual void MarkSequencePoint(ISymbolDocumentWriter document, int startLine, int startColumn, int endLine, int endColumn)
1237  {
1238  if (startLine == 0 || startLine < 0 || endLine == 0 || endLine < 0)
1239  {
1240  throw new ArgumentOutOfRangeException("startLine");
1241  }
1242  m_LineNumberInfo.AddLineNumberInfo(document, m_length, startLine, startColumn, endLine, endColumn);
1243  }
1244 
1247  public virtual void BeginScope()
1248  {
1249  m_ScopeTree.AddScopeInfo(ScopeAction.Open, m_length);
1250  }
1251 
1254  public virtual void EndScope()
1255  {
1256  m_ScopeTree.AddScopeInfo(ScopeAction.Close, m_length);
1257  }
1258 
1262  void _ILGenerator.GetTypeInfoCount(out uint pcTInfo)
1263  {
1264  throw new NotImplementedException();
1265  }
1266 
1272  void _ILGenerator.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
1273  {
1274  throw new NotImplementedException();
1275  }
1276 
1284  void _ILGenerator.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
1285  {
1286  throw new NotImplementedException();
1287  }
1288 
1299  void _ILGenerator.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
1300  {
1301  throw new NotImplementedException();
1302  }
1303  }
1304 }
void AddArgument(Type clsArgument)
Adds an argument to the signature.
OperandType OperandType
The operand type of an intermediate language (IL) instruction.
Definition: OpCode.cs:63
static readonly OpCode Throw
Throws the exception object currently on the evaluation stack.
Definition: OpCodes.cs:489
Represents the standard input, output, and error streams for console applications....
Definition: Console.cs:15
virtual bool IsGenericTypeDefinition
Gets a value indicating whether the current T:System.Type represents a generic type definition,...
Definition: Type.cs:579
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
virtual void MarkSequencePoint(ISymbolDocumentWriter document, int startLine, int startColumn, int endLine, int endColumn)
Marks a sequence point in the Microsoft intermediate language (MSIL) stream.
virtual void Emit(OpCode opcode, SignatureHelper signature)
Puts the specified instruction and a signature token onto the Microsoft intermediate language (MSIL) ...
Definition: ILGenerator.cs:572
static readonly OpCode Endfinally
Transfers control from the fault or finally clause of an exception block back to the Common Language ...
Definition: OpCodes.cs:757
virtual void MarkLabel(Label loc)
Marks the Microsoft intermediate language (MSIL) stream's current position with the given label.
virtual int ILOffset
Gets the current offset, in bytes, in the Microsoft intermediate language (MSIL) stream that is being...
Definition: ILGenerator.cs:68
Describes and represents an enumeration type.
Definition: EnumBuilder.cs:13
abstract Type FieldType
Gets the type of this field object.
Definition: FieldInfo.cs:34
void GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
Maps a set of names to a corresponding set of dispatch identifiers.
static readonly OpCode Ldarg
Loads an argument (referenced by a specified index value) onto the stack.
Definition: OpCodes.cs:841
OperandType
Describes the operand type of Microsoft intermediate language (MSIL) instruction.
Definition: OperandType.cs:9
Discovers the attributes of a method and provides access to method metadata.
Definition: MethodInfo.cs:13
virtual unsafe void Emit(OpCode opcode, float arg)
Puts the specified instruction and numerical argument onto the Microsoft intermediate language (MSIL)...
Definition: ILGenerator.cs:665
static readonly OpCode Stloc_3
Pops the current value from the top of the evaluation stack and stores it in a the local variable lis...
Definition: OpCodes.cs:64
virtual void EndScope()
Ends a lexical scope.
Discovers the attributes of a class constructor and provides access to constructor metadata.
static readonly OpCode Ldloc_2
Loads the local variable at index 2 onto the evaluation stack.
Definition: OpCodes.cs:44
Discovers the attributes of a field and provides access to field metadata.
Definition: FieldInfo.cs:15
Definition: __Canon.cs:3
virtual Type ReturnType
Gets the return type of this method.
Definition: MethodInfo.cs:23
virtual LocalBuilder DeclareLocal(Type localType, bool pinned)
Declares a local variable of the specified type, optionally pinning the object referred to by the var...
The exception that is thrown when the value of an argument is outside the allowable range of values a...
virtual void Emit(OpCode opcode, MethodInfo meth)
Puts the specified instruction onto the Microsoft intermediate language (MSIL) stream followed by the...
Definition: ILGenerator.cs:420
StackBehaviour StackBehaviourPush
How the intermediate language (IL) instruction pushes operand onto the stack.
Definition: OpCode.cs:111
override bool Equals(object obj)
Tests whether the given object is equal to this Opcode.
Definition: OpCode.cs:215
CallingConvention
Specifies the calling convention required to call methods implemented in unmanaged code.
ConstructorInfo GetConstructor(BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
Searches for a constructor whose parameters match the specified argument types and modifiers,...
Definition: Type.cs:1378
virtual void BeginScope()
Begins a lexical scope.
Provides methods for building signatures.
Exposes the T:System.Reflection.Emit.ILGenerator class to unmanaged code.
Definition: _ILGenerator.cs:11
virtual void EmitCalli(OpCode opcode, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Type[] optionalParameterTypes)
Puts a F:System.Reflection.Emit.OpCodes.Calli instruction onto the Microsoft intermediate language (M...
Definition: ILGenerator.cs:450
static readonly OpCode Ldloca_S
Loads the address of the local variable at a specific index onto the evaluation stack,...
Definition: OpCodes.cs:84
SignatureToken GetSignatureToken(SignatureHelper sigHelper)
Defines a token for the signature that is defined by the specified T:System.Reflection....
virtual LocalBuilder DeclareLocal(Type localType)
Declares a local variable of the specified type.
virtual void BeginFaultBlock()
Begins an exception fault block in the Microsoft intermediate language (MSIL) stream.
Definition: ILGenerator.cs:971
bool IsStatic
Gets a value indicating whether the method is static.
Definition: MethodBase.cs:227
static bool TakesSingleByteArgument(OpCode inst)
Returns true or false if the supplied opcode takes a single byte argument.
Definition: OpCodes.cs:924
virtual bool IsSubclassOf(Type c)
Determines whether the current T:System.Type derives from the specified T:System.Type.
Definition: Type.cs:2664
static readonly OpCode Stloc_0
Pops the current value from the top of the evaluation stack and stores it in a the local variable lis...
Definition: OpCodes.cs:52
virtual unsafe void Emit(OpCode opcode, double arg)
Puts the specified instruction and numerical argument onto the Microsoft intermediate language (MSIL)...
Definition: ILGenerator.cs:680
void Emit(OpCode opcode, sbyte arg)
Puts the specified instruction and character argument onto the Microsoft intermediate language (MSIL)...
Definition: ILGenerator.cs:377
static readonly OpCode Ldtoken
Converts a metadata token to its runtime representation, pushing it onto the evaluation stack.
Definition: OpCodes.cs:709
Generates Microsoft intermediate language (MSIL) instructions.
Definition: ILGenerator.cs:12
virtual void EndExceptionBlock()
Ends an exception block.
Definition: ILGenerator.cs:888
CallingConventions
Defines the valid calling conventions for a method.
static readonly OpCode Endfilter
Transfers control from the filter clause of an exception back to the Common Language Infrastructure (...
Definition: OpCodes.cs:869
virtual void Emit(OpCode opcode, Label[] labels)
Puts the specified instruction onto the Microsoft intermediate language (MSIL) stream and leaves spac...
Definition: ILGenerator.cs:720
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
virtual void EmitWriteLine(FieldInfo fld)
Emits the Microsoft intermediate language (MSIL) necessary to call Overload:System....
Represents a globally unique identifier (GUID).To browse the .NET Framework source code for this type...
Definition: Guid.cs:14
virtual void Emit(OpCode opcode, LocalBuilder local)
Puts the specified instruction onto the Microsoft intermediate language (MSIL) stream followed by the...
Definition: ILGenerator.cs:776
virtual void EmitCall(OpCode opcode, MethodInfo methodInfo, Type[] optionalParameterTypes)
Puts a call or callvirt instruction onto the Microsoft intermediate language (MSIL) stream to call a ...
Definition: ILGenerator.cs:531
static readonly OpCode Ldloca
Loads the address of the local variable at a specific index onto the evaluation stack.
Definition: OpCodes.cs:857
virtual void BeginExceptFilterBlock()
Begins an exception block for a filtered exception.
Definition: ILGenerator.cs:924
FieldToken GetFieldToken(FieldInfo field)
Returns the token used to identify the specified field within this module.
virtual Label BeginExceptionBlock()
Begins an exception block for a non-filtered exception.
Definition: ILGenerator.cs:860
Defines and creates new instances of classes during run time.
Definition: TypeBuilder.cs:15
static readonly Type [] EmptyTypes
Represents an empty array of type T:System.Type. This field is read-only.
Definition: Type.cs:38
virtual void Emit(OpCode opcode, int arg)
Puts the specified instruction and numerical argument onto the Microsoft intermediate language (MSIL)...
Definition: ILGenerator.cs:405
virtual void EmitWriteLine(LocalBuilder localBuilder)
Emits the Microsoft intermediate language (MSIL) necessary to call Overload:System....
Defines and represents a module in a dynamic assembly.
void GetTypeInfoCount(out uint pcTInfo)
Retrieves the number of type information interfaces that an object provides (either 0 or 1).
FieldAttributes
Specifies flags that describe the attributes of a field.
virtual void BeginCatchBlock(Type exceptionType)
Begins a catch block.
Definition: ILGenerator.cs:942
virtual void Emit(OpCode opcode, ConstructorInfo con)
Puts the specified instruction and metadata token for the specified constructor onto the Microsoft in...
Definition: ILGenerator.cs:600
Represents a writer that can write a sequential series of characters. This class is abstract.
Definition: TextWriter.cs:15
ILGenerator GetILGenerator()
Returns an ILGenerator for this method with a default Microsoft intermediate language (MSIL) stream s...
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
Represents a local variable within a method or constructor.
Definition: LocalBuilder.cs:9
static readonly OpCode Ldloc_S
Loads the local variable at a specific index onto the evaluation stack, short form.
Definition: OpCodes.cs:80
virtual void Emit(OpCode opcode, Type cls)
Puts the specified instruction onto the Microsoft intermediate language (MSIL) stream followed by the...
Definition: ILGenerator.cs:633
static readonly OpCode Call
Calls the method indicated by the passed method descriptor.
Definition: OpCodes.cs:168
static readonly OpCode Stloc_1
Pops the current value from the top of the evaluation stack and stores it in a the local variable lis...
Definition: OpCodes.cs:56
static readonly OpCode Ldsfld
Pushes the value of a static field onto the evaluation stack.
Definition: OpCodes.cs:505
virtual void Emit(OpCode opcode, FieldInfo field)
Puts the specified instruction and metadata token for the specified field onto the Microsoft intermed...
Definition: ILGenerator.cs:744
static SignatureHelper GetLocalVarSigHelper()
Returns a signature helper for a local variable.
Defines and represents a method (or constructor) on a dynamic class.
Represents a label in the instruction stream. Label is used in conjunction with the T:System....
Definition: Label.cs:8
Provides field representations of the Microsoft Intermediate Language (MSIL) instructions for emissio...
Definition: OpCodes.cs:8
static readonly OpCode Calli
Calls the method indicated on the evaluation stack (as a pointer to an entry point) with arguments de...
Definition: OpCodes.cs:172
abstract FieldAttributes Attributes
Gets the attributes associated with this field.
Definition: FieldInfo.cs:43
int Token
Retrieves the metadata token for the local variable signature for this method.
The exception that is thrown when one of the arguments provided to a method is not valid.
static readonly OpCode Ldloc_1
Loads the local variable at index 1 onto the evaluation stack.
Definition: OpCodes.cs:40
static void Copy(Array sourceArray, Array destinationArray, int length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
Definition: Array.cs:1275
virtual void Emit(OpCode opcode)
Puts the specified instruction onto the stream of instructions.
Definition: ILGenerator.cs:357
StackBehaviour StackBehaviourPop
How the intermediate language (IL) instruction pops the stack.
Definition: OpCode.cs:99
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Definition: Exception.cs:22
virtual void ThrowException(Type excType)
Emits an instruction to throw an exception.
static readonly OpCode Ldfld
Finds the value of a field in the object whose reference is currently on the evaluation stack.
Definition: OpCodes.cs:493
static readonly OpCode Ldloc_3
Loads the local variable at index 3 onto the evaluation stack.
Definition: OpCodes.cs:48
virtual void Emit(OpCode opcode, string str)
Puts the specified instruction onto the Microsoft intermediate language (MSIL) stream followed by the...
Definition: ILGenerator.cs:757
virtual Module Module
Gets the module in which the type that declares the member represented by the current T:System....
Definition: MemberInfo.cs:78
Describes an intermediate language (IL) instruction.
Definition: OpCode.cs:9
Represents a document referenced by a symbol store.
static readonly OpCode Stloc_S
Pops the current value from the top of the evaluation stack and stores it in a the local variable lis...
Definition: OpCodes.cs:88
static readonly OpCode Ldftn
Pushes an unmanaged pointer (type native int) to the native code implementing a specific method onto ...
Definition: OpCodes.cs:833
virtual void Emit(OpCode opcode, byte arg)
Puts the specified instruction and character argument onto the Microsoft intermediate language (MSIL)...
Definition: ILGenerator.cs:366
virtual Label DefineLabel()
Declares a new label.
static readonly OpCode Callvirt
Calls a late-bound method on an object, pushing the return value onto the evaluation stack.
Definition: OpCodes.cs:452
The exception that is thrown when a method call is invalid for the object's current state.
static SignatureHelper GetMethodSigHelper(Module mod, Type returnType, Type[] parameterTypes)
Returns a signature helper for a method with a standard calling convention, given the method's module...
virtual void Emit(OpCode opcode, long arg)
Puts the specified instruction and numerical argument onto the Microsoft intermediate language (MSIL)...
Definition: ILGenerator.cs:647
virtual void UsingNamespace(string usingNamespace)
Specifies the namespace to be used in evaluating locals and watches for the current active lexical sc...
static readonly OpCode Ldvirtftn
Pushes an unmanaged pointer (type native int) to the native code implementing a particular virtual me...
Definition: OpCodes.cs:837
static readonly OpCode Ldloc
Loads the local variable at a specific index onto the evaluation stack.
Definition: OpCodes.cs:853
ClassInterfaceType
Identifies the type of class interface that is generated for a class.
StackBehaviour
Describes how values are pushed onto a stack or popped off a stack.
virtual void EmitWriteLine(string value)
Emits the Microsoft intermediate language (MSIL) to call Overload:System.Console.WriteLine with a str...
int Token
Retrieves the metadata token for this class.
Definition: TypeToken.cs:17
void GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
Retrieves the type information for an object, which can be used to get the type information for an in...
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
static readonly OpCode Ldloc_0
Loads the local variable at index 0 onto the evaluation stack.
Definition: OpCodes.cs:36
void Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
Provides access to properties and methods exposed by an object.
static readonly OpCode Leave
Exits a protected region of code, unconditionally transferring control to a specific target instructi...
Definition: OpCodes.cs:761
static readonly OpCode Newobj
Creates a new object or a new instance of a value type, pushing an object reference (type O) onto the...
Definition: OpCodes.cs:468
virtual void EmitCalli(OpCode opcode, CallingConvention unmanagedCallConv, Type returnType, Type[] parameterTypes)
Puts a F:System.Reflection.Emit.OpCodes.Calli instruction onto the Microsoft intermediate language (M...
Definition: ILGenerator.cs:488
TypeToken GetTypeToken(Type type)
Returns the token used to identify the specified type within this module.
The exception that is thrown when a requested method or operation is not implemented.
static readonly OpCode Stloc_2
Pops the current value from the top of the evaluation stack and stores it in a the local variable lis...
Definition: OpCodes.cs:60
int Token
Retrieves the metadata token for this field.
Definition: FieldToken.cs:19
override Type LocalType
Gets the type of the local variable.
Definition: LocalBuilder.cs:26
virtual void Emit(OpCode opcode, short arg)
Puts the specified instruction and numerical argument onto the Microsoft intermediate language (MSIL)...
Definition: ILGenerator.cs:394
static readonly OpCode Ldstr
Pushes a new object reference to a string literal stored in the metadata.
Definition: OpCodes.cs:464
static readonly OpCode Stloc
Pops the current value from the top of the evaluation stack and stores it in a the local variable lis...
Definition: OpCodes.cs:861
virtual void BeginFinallyBlock()
Begins a finally block in the Microsoft intermediate language (MSIL) instruction stream.
Definition: ILGenerator.cs:985
virtual void Emit(OpCode opcode, Label label)
Puts the specified instruction onto the Microsoft intermediate language (MSIL) stream and leaves spac...
Definition: ILGenerator.cs:698