mscorlib(4.0.0.0) API with additions
ModuleBuilder.cs
4 using System.IO;
5 using System.Resources;
8 using System.Security;
11 
12 namespace System.Reflection.Emit
13 {
15  [ClassInterface(ClassInterfaceType.None)]
16  [ComDefaultInterface(typeof(_ModuleBuilder))]
17  [ComVisible(true)]
18  [HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
20  {
21  private Dictionary<string, Type> m_TypeBuilderDict;
22 
23  private ISymbolWriter m_iSymWriter;
24 
25  internal ModuleBuilderData m_moduleData;
26 
27  private MethodToken m_EntryPoint;
28 
29  internal InternalModuleBuilder m_internalModuleBuilder;
30 
31  private AssemblyBuilder m_assemblyBuilder;
32 
33  internal AssemblyBuilder ContainingAssemblyBuilder => m_assemblyBuilder;
34 
35  internal object SyncRoot => ContainingAssemblyBuilder.SyncRoot;
36 
37  internal InternalModuleBuilder InternalModule => m_internalModuleBuilder;
38 
41  public override string FullyQualifiedName
42  {
43  [SecuritySafeCritical]
44  get
45  {
46  string text = m_moduleData.m_strFileName;
47  if (text == null)
48  {
49  return null;
50  }
51  if (ContainingAssemblyBuilder.m_assemblyData.m_strDir != null)
52  {
53  text = Path.Combine(ContainingAssemblyBuilder.m_assemblyData.m_strDir, text);
54  text = Path.UnsafeGetFullPath(text);
55  }
56  if (ContainingAssemblyBuilder.m_assemblyData.m_strDir != null && text != null)
57  {
58  new FileIOPermission(FileIOPermissionAccess.PathDiscovery, text).Demand();
59  }
60  return text;
61  }
62  }
63 
66  public override int MDStreamVersion => InternalModule.MDStreamVersion;
67 
70  public override Guid ModuleVersionId => InternalModule.ModuleVersionId;
71 
74  public override int MetadataToken => InternalModule.MetadataToken;
75 
78  public override string ScopeName => InternalModule.ScopeName;
79 
82  public override string Name => InternalModule.Name;
83 
86  public override Assembly Assembly => m_assemblyBuilder;
87 
88  [MethodImpl(MethodImplOptions.InternalCall)]
89  internal static extern IntPtr nCreateISymWriterForDynamicModule(Module module, string filename);
90 
91  internal static string UnmangleTypeName(string typeName)
92  {
93  int startIndex = typeName.Length - 1;
94  while (true)
95  {
96  startIndex = typeName.LastIndexOf('+', startIndex);
97  if (startIndex == -1)
98  {
99  break;
100  }
101  bool flag = true;
102  int num = startIndex;
103  while (typeName[--num] == '\\')
104  {
105  flag = !flag;
106  }
107  if (flag)
108  {
109  break;
110  }
111  startIndex = num;
112  }
113  return typeName.Substring(startIndex + 1);
114  }
115 
116  internal ModuleBuilder(AssemblyBuilder assemblyBuilder, InternalModuleBuilder internalModuleBuilder)
117  {
118  m_internalModuleBuilder = internalModuleBuilder;
119  m_assemblyBuilder = assemblyBuilder;
120  }
121 
122  internal void AddType(string name, Type type)
123  {
124  m_TypeBuilderDict.Add(name, type);
125  }
126 
127  internal void CheckTypeNameConflict(string strTypeName, Type enclosingType)
128  {
129  Type value = null;
130  if (m_TypeBuilderDict.TryGetValue(strTypeName, out value) && (object)value.DeclaringType == enclosingType)
131  {
132  throw new ArgumentException(Environment.GetResourceString("Argument_DuplicateTypeName"));
133  }
134  }
135 
136  private Type GetType(string strFormat, Type baseType)
137  {
138  if (strFormat == null || strFormat.Equals(string.Empty))
139  {
140  return baseType;
141  }
142  char[] bFormat = strFormat.ToCharArray();
143  return SymbolType.FormCompoundType(bFormat, baseType, 0);
144  }
145 
146  internal void CheckContext(params Type[][] typess)
147  {
148  ContainingAssemblyBuilder.CheckContext(typess);
149  }
150 
151  internal void CheckContext(params Type[] types)
152  {
153  ContainingAssemblyBuilder.CheckContext(types);
154  }
155 
156  [DllImport("QCall", CharSet = CharSet.Unicode)]
157  [SecurityCritical]
158  [SuppressUnmanagedCodeSecurity]
159  private static extern int GetTypeRef(RuntimeModule module, string strFullName, RuntimeModule refedModule, string strRefedModuleFileName, int tkResolution);
160 
161  [DllImport("QCall", CharSet = CharSet.Unicode)]
162  [SecurityCritical]
163  [SuppressUnmanagedCodeSecurity]
164  private static extern int GetMemberRef(RuntimeModule module, RuntimeModule refedModule, int tr, int defToken);
165 
166  [SecurityCritical]
167  private int GetMemberRef(Module refedModule, int tr, int defToken)
168  {
169  return GetMemberRef(GetNativeHandle(), GetRuntimeModuleFromModule(refedModule).GetNativeHandle(), tr, defToken);
170  }
171 
172  [DllImport("QCall", CharSet = CharSet.Unicode)]
173  [SecurityCritical]
174  [SuppressUnmanagedCodeSecurity]
175  private static extern int GetMemberRefFromSignature(RuntimeModule module, int tr, string methodName, byte[] signature, int length);
176 
177  [SecurityCritical]
178  private int GetMemberRefFromSignature(int tr, string methodName, byte[] signature, int length)
179  {
180  return GetMemberRefFromSignature(GetNativeHandle(), tr, methodName, signature, length);
181  }
182 
183  [DllImport("QCall", CharSet = CharSet.Unicode)]
184  [SecurityCritical]
185  [SuppressUnmanagedCodeSecurity]
186  private static extern int GetMemberRefOfMethodInfo(RuntimeModule module, int tr, IRuntimeMethodInfo method);
187 
188  [SecurityCritical]
189  private int GetMemberRefOfMethodInfo(int tr, RuntimeMethodInfo method)
190  {
191  if (ContainingAssemblyBuilder.ProfileAPICheck && (method.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
192  {
193  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", method.FullName));
194  }
195  return GetMemberRefOfMethodInfo(GetNativeHandle(), tr, method);
196  }
197 
198  [SecurityCritical]
199  private int GetMemberRefOfMethodInfo(int tr, RuntimeConstructorInfo method)
200  {
201  if (ContainingAssemblyBuilder.ProfileAPICheck && (method.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
202  {
203  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", method.FullName));
204  }
205  return GetMemberRefOfMethodInfo(GetNativeHandle(), tr, method);
206  }
207 
208  [DllImport("QCall", CharSet = CharSet.Unicode)]
209  [SecurityCritical]
210  [SuppressUnmanagedCodeSecurity]
211  private static extern int GetMemberRefOfFieldInfo(RuntimeModule module, int tkType, RuntimeTypeHandle declaringType, int tkField);
212 
213  [SecurityCritical]
214  private int GetMemberRefOfFieldInfo(int tkType, RuntimeTypeHandle declaringType, RuntimeFieldInfo runtimeField)
215  {
216  if (ContainingAssemblyBuilder.ProfileAPICheck)
217  {
218  RtFieldInfo rtFieldInfo = runtimeField as RtFieldInfo;
219  if (rtFieldInfo != null && (rtFieldInfo.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
220  {
221  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtFieldInfo.FullName));
222  }
223  }
224  return GetMemberRefOfFieldInfo(GetNativeHandle(), tkType, declaringType, runtimeField.MetadataToken);
225  }
226 
227  [DllImport("QCall", CharSet = CharSet.Unicode)]
228  [SecurityCritical]
229  [SuppressUnmanagedCodeSecurity]
230  private static extern int GetTokenFromTypeSpec(RuntimeModule pModule, byte[] signature, int length);
231 
232  [SecurityCritical]
233  private int GetTokenFromTypeSpec(byte[] signature, int length)
234  {
235  return GetTokenFromTypeSpec(GetNativeHandle(), signature, length);
236  }
237 
238  [DllImport("QCall", CharSet = CharSet.Unicode)]
239  [SecurityCritical]
240  [SuppressUnmanagedCodeSecurity]
241  private static extern int GetArrayMethodToken(RuntimeModule module, int tkTypeSpec, string methodName, byte[] signature, int sigLength);
242 
243  [DllImport("QCall", CharSet = CharSet.Unicode)]
244  [SecurityCritical]
245  [SuppressUnmanagedCodeSecurity]
246  private static extern int GetStringConstant(RuntimeModule module, string str, int length);
247 
248  [DllImport("QCall", CharSet = CharSet.Unicode)]
249  [SecurityCritical]
250  [SuppressUnmanagedCodeSecurity]
251  private static extern void PreSavePEFile(RuntimeModule module, int portableExecutableKind, int imageFileMachine);
252 
253  [DllImport("QCall", CharSet = CharSet.Unicode)]
254  [SecurityCritical]
255  [SuppressUnmanagedCodeSecurity]
256  private static extern void SavePEFile(RuntimeModule module, string fileName, int entryPoint, int isExe, bool isManifestFile);
257 
258  [DllImport("QCall", CharSet = CharSet.Unicode)]
259  [SecurityCritical]
260  [SuppressUnmanagedCodeSecurity]
261  private static extern void AddResource(RuntimeModule module, string strName, byte[] resBytes, int resByteCount, int tkFile, int attribute, int portableExecutableKind, int imageFileMachine);
262 
263  [DllImport("QCall", CharSet = CharSet.Unicode)]
264  [SecurityCritical]
265  [SuppressUnmanagedCodeSecurity]
266  private static extern void SetModuleName(RuntimeModule module, string strModuleName);
267 
268  [DllImport("QCall", CharSet = CharSet.Unicode)]
269  [SecurityCritical]
270  [SuppressUnmanagedCodeSecurity]
271  internal static extern void SetFieldRVAContent(RuntimeModule module, int fdToken, byte[] data, int length);
272 
273  [DllImport("QCall", CharSet = CharSet.Unicode)]
274  [SecurityCritical]
275  [SuppressUnmanagedCodeSecurity]
276  private static extern void DefineNativeResourceFile(RuntimeModule module, string strFilename, int portableExecutableKind, int ImageFileMachine);
277 
278  [DllImport("QCall", CharSet = CharSet.Unicode)]
279  [SecurityCritical]
280  [SuppressUnmanagedCodeSecurity]
281  private static extern void DefineNativeResourceBytes(RuntimeModule module, byte[] pbResource, int cbResource, int portableExecutableKind, int imageFileMachine);
282 
283  [SecurityCritical]
284  internal void DefineNativeResource(PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine)
285  {
286  string strResourceFileName = m_moduleData.m_strResourceFileName;
287  byte[] resourceBytes = m_moduleData.m_resourceBytes;
288  if (strResourceFileName != null)
289  {
290  DefineNativeResourceFile(GetNativeHandle(), strResourceFileName, (int)portableExecutableKind, (int)imageFileMachine);
291  }
292  else if (resourceBytes != null)
293  {
294  DefineNativeResourceBytes(GetNativeHandle(), resourceBytes, resourceBytes.Length, (int)portableExecutableKind, (int)imageFileMachine);
295  }
296  }
297 
298  internal virtual Type FindTypeBuilderWithName(string strTypeName, bool ignoreCase)
299  {
300  Type value;
301  if (ignoreCase)
302  {
303  foreach (string key in m_TypeBuilderDict.Keys)
304  {
305  if (string.Compare(key, strTypeName, StringComparison.OrdinalIgnoreCase) == 0)
306  {
307  return m_TypeBuilderDict[key];
308  }
309  }
310  }
311  else if (m_TypeBuilderDict.TryGetValue(strTypeName, out value))
312  {
313  return value;
314  }
315  return null;
316  }
317 
318  internal void SetEntryPoint(MethodToken entryPoint)
319  {
320  m_EntryPoint = entryPoint;
321  }
322 
323  [SecurityCritical]
324  internal void PreSave(string fileName, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine)
325  {
326  if (m_moduleData.m_isSaved)
327  {
328  throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, Environment.GetResourceString("InvalidOperation_ModuleHasBeenSaved"), m_moduleData.m_strModuleName));
329  }
330  if (!m_moduleData.m_fGlobalBeenCreated && m_moduleData.m_fHasGlobal)
331  {
332  throw new NotSupportedException(Environment.GetResourceString("NotSupported_GlobalFunctionNotBaked"));
333  }
334  foreach (Type value in m_TypeBuilderDict.Values)
335  {
336  TypeBuilder typeBuilder;
337  if (value is TypeBuilder)
338  {
339  typeBuilder = (TypeBuilder)value;
340  }
341  else
342  {
343  EnumBuilder enumBuilder = (EnumBuilder)value;
344  typeBuilder = enumBuilder.m_typeBuilder;
345  }
346  if (!typeBuilder.IsCreated())
347  {
348  throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, Environment.GetResourceString("NotSupported_NotAllTypesAreBaked"), typeBuilder.FullName));
349  }
350  }
351  PreSavePEFile(GetNativeHandle(), (int)portableExecutableKind, (int)imageFileMachine);
352  }
353 
354  [SecurityCritical]
355  internal void Save(string fileName, bool isAssemblyFile, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine)
356  {
357  if (m_moduleData.m_embeddedRes != null)
358  {
359  for (ResWriterData resWriterData = m_moduleData.m_embeddedRes; resWriterData != null; resWriterData = resWriterData.m_nextResWriter)
360  {
361  if (resWriterData.m_resWriter != null)
362  {
363  resWriterData.m_resWriter.Generate();
364  }
365  byte[] array = new byte[resWriterData.m_memoryStream.Length];
366  resWriterData.m_memoryStream.Flush();
367  resWriterData.m_memoryStream.Position = 0L;
368  resWriterData.m_memoryStream.Read(array, 0, array.Length);
369  AddResource(GetNativeHandle(), resWriterData.m_strName, array, array.Length, m_moduleData.FileToken, (int)resWriterData.m_attribute, (int)portableExecutableKind, (int)imageFileMachine);
370  }
371  }
372  DefineNativeResource(portableExecutableKind, imageFileMachine);
373  PEFileKinds isExe = (!isAssemblyFile) ? PEFileKinds.Dll : ContainingAssemblyBuilder.m_assemblyData.m_peFileKind;
374  SavePEFile(GetNativeHandle(), fileName, m_EntryPoint.Token, (int)isExe, isAssemblyFile);
375  m_moduleData.m_isSaved = true;
376  }
377 
378  [SecurityCritical]
379  private int GetTypeRefNested(Type type, Module refedModule, string strRefedModuleFileName)
380  {
381  Type declaringType = type.DeclaringType;
382  int tkResolution = 0;
383  string text = type.FullName;
384  if (declaringType != null)
385  {
386  tkResolution = GetTypeRefNested(declaringType, refedModule, strRefedModuleFileName);
387  text = UnmangleTypeName(text);
388  }
389  if (ContainingAssemblyBuilder.ProfileAPICheck)
390  {
391  RuntimeType runtimeType = type as RuntimeType;
392  if (runtimeType != null && (runtimeType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
393  {
394  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", runtimeType.FullName));
395  }
396  }
397  return GetTypeRef(GetNativeHandle(), text, GetRuntimeModuleFromModule(refedModule).GetNativeHandle(), strRefedModuleFileName, tkResolution);
398  }
399 
400  [SecurityCritical]
401  internal MethodToken InternalGetConstructorToken(ConstructorInfo con, bool usingRef)
402  {
403  if (con == null)
404  {
405  throw new ArgumentNullException("con");
406  }
407  int num = 0;
408  ConstructorBuilder constructorBuilder = null;
409  ConstructorOnTypeBuilderInstantiation constructorOnTypeBuilderInstantiation = null;
410  RuntimeConstructorInfo runtimeConstructorInfo = null;
411  if ((constructorBuilder = (con as ConstructorBuilder)) != null)
412  {
413  if (!usingRef && constructorBuilder.Module.Equals(this))
414  {
415  return constructorBuilder.GetToken();
416  }
417  int token = GetTypeTokenInternal(con.ReflectedType).Token;
418  num = GetMemberRef(con.ReflectedType.Module, token, constructorBuilder.GetToken().Token);
419  }
420  else if ((constructorOnTypeBuilderInstantiation = (con as ConstructorOnTypeBuilderInstantiation)) != null)
421  {
422  if (usingRef)
423  {
424  throw new InvalidOperationException();
425  }
426  int token = GetTypeTokenInternal(con.DeclaringType).Token;
427  num = GetMemberRef(con.DeclaringType.Module, token, constructorOnTypeBuilderInstantiation.MetadataTokenInternal);
428  }
429  else if ((runtimeConstructorInfo = (con as RuntimeConstructorInfo)) != null && !con.ReflectedType.IsArray)
430  {
431  int token = GetTypeTokenInternal(con.ReflectedType).Token;
432  num = GetMemberRefOfMethodInfo(token, runtimeConstructorInfo);
433  }
434  else
435  {
436  ParameterInfo[] parameters = con.GetParameters();
437  if (parameters == null)
438  {
439  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidConstructorInfo"));
440  }
441  int num2 = parameters.Length;
442  Type[] array = new Type[num2];
443  Type[][] array2 = new Type[num2][];
444  Type[][] array3 = new Type[num2][];
445  for (int i = 0; i < num2; i++)
446  {
447  if (parameters[i] == null)
448  {
449  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidConstructorInfo"));
450  }
451  array[i] = parameters[i].ParameterType;
452  array2[i] = parameters[i].GetRequiredCustomModifiers();
453  array3[i] = parameters[i].GetOptionalCustomModifiers();
454  }
455  int token = GetTypeTokenInternal(con.ReflectedType).Token;
456  SignatureHelper methodSigHelper = SignatureHelper.GetMethodSigHelper(this, con.CallingConvention, null, null, null, array, array2, array3);
457  int length;
458  byte[] signature = methodSigHelper.InternalGetSignature(out length);
459  num = GetMemberRefFromSignature(token, con.Name, signature, length);
460  }
461  return new MethodToken(num);
462  }
463 
464  [SecurityCritical]
465  internal void Init(string strModuleName, string strFileName, int tkFile)
466  {
467  m_moduleData = new ModuleBuilderData(this, strModuleName, strFileName, tkFile);
468  m_TypeBuilderDict = new Dictionary<string, Type>();
469  }
470 
471  [SecurityCritical]
472  internal void ModifyModuleName(string name)
473  {
474  m_moduleData.ModifyModuleName(name);
475  SetModuleName(GetNativeHandle(), name);
476  }
477 
478  internal void SetSymWriter(ISymbolWriter writer)
479  {
480  m_iSymWriter = writer;
481  }
482 
483  internal override ModuleHandle GetModuleHandle()
484  {
485  return new ModuleHandle(GetNativeHandle());
486  }
487 
488  internal RuntimeModule GetNativeHandle()
489  {
490  return InternalModule.GetNativeHandle();
491  }
492 
493  private static RuntimeModule GetRuntimeModuleFromModule(Module m)
494  {
495  ModuleBuilder moduleBuilder = m as ModuleBuilder;
496  if (moduleBuilder != null)
497  {
498  return moduleBuilder.InternalModule;
499  }
500  return m as RuntimeModule;
501  }
502 
503  [SecurityCritical]
504  private int GetMemberRefToken(MethodBase method, IEnumerable<Type> optionalParameterTypes)
505  {
506  int cGenericParameters = 0;
507  if (method.IsGenericMethod)
508  {
509  if (!method.IsGenericMethodDefinition)
510  {
511  throw new InvalidOperationException();
512  }
513  cGenericParameters = method.GetGenericArguments().Length;
514  }
515  if (optionalParameterTypes != null && (method.CallingConvention & CallingConventions.VarArgs) == (CallingConventions)0)
516  {
517  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotAVarArgCallingConvention"));
518  }
519  MethodInfo methodInfo = method as MethodInfo;
520  Type[] parameterTypes;
521  Type methodBaseReturnType;
522  if (method.DeclaringType.IsGenericType)
523  {
524  MethodBase methodBase = null;
525  MethodOnTypeBuilderInstantiation methodOnTypeBuilderInstantiation;
526  ConstructorOnTypeBuilderInstantiation constructorOnTypeBuilderInstantiation;
527  if ((methodOnTypeBuilderInstantiation = (method as MethodOnTypeBuilderInstantiation)) != null)
528  {
529  methodBase = methodOnTypeBuilderInstantiation.m_method;
530  }
531  else if ((constructorOnTypeBuilderInstantiation = (method as ConstructorOnTypeBuilderInstantiation)) != null)
532  {
533  methodBase = constructorOnTypeBuilderInstantiation.m_ctor;
534  }
535  else if (method is MethodBuilder || method is ConstructorBuilder)
536  {
537  methodBase = method;
538  }
539  else if (method.IsGenericMethod)
540  {
541  methodBase = methodInfo.GetGenericMethodDefinition();
542  methodBase = methodBase.Module.ResolveMethod(method.MetadataToken, (methodBase.DeclaringType != null) ? methodBase.DeclaringType.GetGenericArguments() : null, methodBase.GetGenericArguments());
543  }
544  else
545  {
546  methodBase = method.Module.ResolveMethod(method.MetadataToken, (method.DeclaringType != null) ? method.DeclaringType.GetGenericArguments() : null, null);
547  }
548  parameterTypes = methodBase.GetParameterTypes();
549  methodBaseReturnType = MethodBuilder.GetMethodBaseReturnType(methodBase);
550  }
551  else
552  {
553  parameterTypes = method.GetParameterTypes();
554  methodBaseReturnType = MethodBuilder.GetMethodBaseReturnType(method);
555  }
556  int length;
557  byte[] signature = GetMemberRefSignature(method.CallingConvention, methodBaseReturnType, parameterTypes, optionalParameterTypes, cGenericParameters).InternalGetSignature(out length);
558  int tr;
559  if (!method.DeclaringType.IsGenericType)
560  {
561  tr = ((!method.Module.Equals(this)) ? GetTypeToken(method.DeclaringType).Token : ((!(methodInfo != null)) ? GetConstructorToken(method as ConstructorInfo).Token : GetMethodToken(methodInfo).Token));
562  }
563  else
564  {
565  int length2;
566  byte[] signature2 = SignatureHelper.GetTypeSigToken(this, method.DeclaringType).InternalGetSignature(out length2);
567  tr = GetTokenFromTypeSpec(signature2, length2);
568  }
569  return GetMemberRefFromSignature(tr, method.Name, signature, length);
570  }
571 
572  [SecurityCritical]
573  internal SignatureHelper GetMemberRefSignature(CallingConventions call, Type returnType, Type[] parameterTypes, IEnumerable<Type> optionalParameterTypes, int cGenericParameters)
574  {
575  int num = (parameterTypes != null) ? parameterTypes.Length : 0;
576  SignatureHelper methodSigHelper = SignatureHelper.GetMethodSigHelper(this, call, returnType, cGenericParameters);
577  for (int i = 0; i < num; i++)
578  {
579  methodSigHelper.AddArgument(parameterTypes[i]);
580  }
581  if (optionalParameterTypes != null)
582  {
583  int num2 = 0;
584  {
585  foreach (Type optionalParameterType in optionalParameterTypes)
586  {
587  if (num2 == 0)
588  {
589  methodSigHelper.AddSentinel();
590  }
591  methodSigHelper.AddArgument(optionalParameterType);
592  num2++;
593  }
594  return methodSigHelper;
595  }
596  }
597  return methodSigHelper;
598  }
599 
604  public override bool Equals(object obj)
605  {
606  return InternalModule.Equals(obj);
607  }
608 
611  public override int GetHashCode()
612  {
613  return InternalModule.GetHashCode();
614  }
615 
619  public override object[] GetCustomAttributes(bool inherit)
620  {
621  return InternalModule.GetCustomAttributes(inherit);
622  }
623 
632  public override object[] GetCustomAttributes(Type attributeType, bool inherit)
633  {
634  return InternalModule.GetCustomAttributes(attributeType, inherit);
635  }
636 
646  public override bool IsDefined(Type attributeType, bool inherit)
647  {
648  return InternalModule.IsDefined(attributeType, inherit);
649  }
650 
654  {
655  return InternalModule.GetCustomAttributesData();
656  }
657 
662  public override Type[] GetTypes()
663  {
664  lock (SyncRoot)
665  {
666  return GetTypesNoLock();
667  }
668  }
669 
670  internal Type[] GetTypesNoLock()
671  {
672  int count = m_TypeBuilderDict.Count;
673  Type[] array = new Type[m_TypeBuilderDict.Count];
674  int num = 0;
675  foreach (Type value in m_TypeBuilderDict.Values)
676  {
677  EnumBuilder enumBuilder = value as EnumBuilder;
678  TypeBuilder typeBuilder = (!(enumBuilder != null)) ? ((TypeBuilder)value) : enumBuilder.m_typeBuilder;
679  if (typeBuilder.IsCreated())
680  {
681  array[num++] = typeBuilder.UnderlyingSystemType;
682  }
683  else
684  {
685  array[num++] = value;
686  }
687  }
688  return array;
689  }
690 
700  [ComVisible(true)]
701  public override Type GetType(string className)
702  {
703  return GetType(className, throwOnError: false, ignoreCase: false);
704  }
705 
715  [ComVisible(true)]
716  public override Type GetType(string className, bool ignoreCase)
717  {
718  return GetType(className, throwOnError: false, ignoreCase);
719  }
720 
734  [ComVisible(true)]
735  public override Type GetType(string className, bool throwOnError, bool ignoreCase)
736  {
737  lock (SyncRoot)
738  {
739  return GetTypeNoLock(className, throwOnError, ignoreCase);
740  }
741  }
742 
743  private Type GetTypeNoLock(string className, bool throwOnError, bool ignoreCase)
744  {
745  Type type = InternalModule.GetType(className, throwOnError, ignoreCase);
746  if (type != null)
747  {
748  return type;
749  }
750  string text = null;
751  string text2 = null;
752  int num = 0;
753  while (num <= className.Length)
754  {
755  int num2 = className.IndexOfAny(new char[3]
756  {
757  '[',
758  '*',
759  '&'
760  }, num);
761  if (num2 == -1)
762  {
763  text = className;
764  text2 = null;
765  break;
766  }
767  int num3 = 0;
768  int num4 = num2 - 1;
769  while (num4 >= 0 && className[num4] == '\\')
770  {
771  num3++;
772  num4--;
773  }
774  if (num3 % 2 == 1)
775  {
776  num = num2 + 1;
777  continue;
778  }
779  text = className.Substring(0, num2);
780  text2 = className.Substring(num2);
781  break;
782  }
783  if (text == null)
784  {
785  text = className;
786  text2 = null;
787  }
788  text = text.Replace("\\\\", "\\").Replace("\\[", "[").Replace("\\*", "*")
789  .Replace("\\&", "&");
790  if (text2 != null)
791  {
792  type = InternalModule.GetType(text, throwOnError: false, ignoreCase);
793  }
794  if (type == null)
795  {
796  type = FindTypeBuilderWithName(text, ignoreCase);
797  if (type == null && Assembly is AssemblyBuilder)
798  {
799  List<ModuleBuilder> moduleBuilderList = ContainingAssemblyBuilder.m_assemblyData.m_moduleBuilderList;
800  int count = moduleBuilderList.Count;
801  for (int i = 0; i < count; i++)
802  {
803  if (!(type == null))
804  {
805  break;
806  }
807  ModuleBuilder moduleBuilder = moduleBuilderList[i];
808  type = moduleBuilder.FindTypeBuilderWithName(text, ignoreCase);
809  }
810  }
811  if (type == null)
812  {
813  return null;
814  }
815  }
816  if (text2 == null)
817  {
818  return type;
819  }
820  return GetType(text2, type);
821  }
822 
830  public override byte[] ResolveSignature(int metadataToken)
831  {
832  return InternalModule.ResolveSignature(metadataToken);
833  }
834 
845  public override MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
846  {
847  return InternalModule.ResolveMethod(metadataToken, genericTypeArguments, genericMethodArguments);
848  }
849 
860  public override FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
861  {
862  return InternalModule.ResolveField(metadataToken, genericTypeArguments, genericMethodArguments);
863  }
864 
875  public override Type ResolveType(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
876  {
877  return InternalModule.ResolveType(metadataToken, genericTypeArguments, genericMethodArguments);
878  }
879 
891  public override MemberInfo ResolveMember(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
892  {
893  return InternalModule.ResolveMember(metadataToken, genericTypeArguments, genericMethodArguments);
894  }
895 
903  public override string ResolveString(int metadataToken)
904  {
905  return InternalModule.ResolveString(metadataToken);
906  }
907 
911  public override void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
912  {
913  InternalModule.GetPEKind(out peKind, out machine);
914  }
915 
919  public override bool IsResource()
920  {
921  return InternalModule.IsResource();
922  }
923 
928  public override FieldInfo[] GetFields(BindingFlags bindingFlags)
929  {
930  return InternalModule.GetFields(bindingFlags);
931  }
932 
938  public override FieldInfo GetField(string name, BindingFlags bindingAttr)
939  {
940  return InternalModule.GetField(name, bindingAttr);
941  }
942 
946  public override MethodInfo[] GetMethods(BindingFlags bindingFlags)
947  {
948  return InternalModule.GetMethods(bindingFlags);
949  }
950 
961  protected override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
962  {
963  return InternalModule.GetMethodInternal(name, bindingAttr, binder, callConvention, types, modifiers);
964  }
965 
969  {
970  return InternalModule.GetSignerCertificate();
971  }
972 
979  [SecuritySafeCritical]
980  public TypeBuilder DefineType(string name)
981  {
982  lock (SyncRoot)
983  {
984  return DefineTypeNoLock(name, TypeAttributes.NotPublic, null, null, PackingSize.Unspecified, 0);
985  }
986  }
987 
995  [SecuritySafeCritical]
996  public TypeBuilder DefineType(string name, TypeAttributes attr)
997  {
998  lock (SyncRoot)
999  {
1000  return DefineTypeNoLock(name, attr, null, null, PackingSize.Unspecified, 0);
1001  }
1002  }
1003 
1012  [SecuritySafeCritical]
1013  public TypeBuilder DefineType(string name, TypeAttributes attr, Type parent)
1014  {
1015  lock (SyncRoot)
1016  {
1017  CheckContext(parent);
1018  return DefineTypeNoLock(name, attr, parent, null, PackingSize.Unspecified, 0);
1019  }
1020  }
1021 
1031  [SecuritySafeCritical]
1032  public TypeBuilder DefineType(string name, TypeAttributes attr, Type parent, int typesize)
1033  {
1034  lock (SyncRoot)
1035  {
1036  return DefineTypeNoLock(name, attr, parent, null, PackingSize.Unspecified, typesize);
1037  }
1038  }
1039 
1050  [SecuritySafeCritical]
1051  public TypeBuilder DefineType(string name, TypeAttributes attr, Type parent, PackingSize packingSize, int typesize)
1052  {
1053  lock (SyncRoot)
1054  {
1055  return DefineTypeNoLock(name, attr, parent, null, packingSize, typesize);
1056  }
1057  }
1058 
1068  [SecuritySafeCritical]
1069  [ComVisible(true)]
1070  public TypeBuilder DefineType(string name, TypeAttributes attr, Type parent, Type[] interfaces)
1071  {
1072  lock (SyncRoot)
1073  {
1074  return DefineTypeNoLock(name, attr, parent, interfaces, PackingSize.Unspecified, 0);
1075  }
1076  }
1077 
1078  [SecurityCritical]
1079  private TypeBuilder DefineTypeNoLock(string name, TypeAttributes attr, Type parent, Type[] interfaces, PackingSize packingSize, int typesize)
1080  {
1081  return new TypeBuilder(name, attr, parent, interfaces, this, packingSize, typesize, null);
1082  }
1083 
1093  [SecuritySafeCritical]
1094  public TypeBuilder DefineType(string name, TypeAttributes attr, Type parent, PackingSize packsize)
1095  {
1096  lock (SyncRoot)
1097  {
1098  return DefineTypeNoLock(name, attr, parent, packsize);
1099  }
1100  }
1101 
1102  [SecurityCritical]
1103  private TypeBuilder DefineTypeNoLock(string name, TypeAttributes attr, Type parent, PackingSize packsize)
1104  {
1105  return new TypeBuilder(name, attr, parent, null, this, packsize, 0, null);
1106  }
1107 
1116  [SecuritySafeCritical]
1117  public EnumBuilder DefineEnum(string name, TypeAttributes visibility, Type underlyingType)
1118  {
1119  CheckContext(underlyingType);
1120  lock (SyncRoot)
1121  {
1122  EnumBuilder enumBuilder = DefineEnumNoLock(name, visibility, underlyingType);
1123  m_TypeBuilderDict[name] = enumBuilder;
1124  return enumBuilder;
1125  }
1126  }
1127 
1128  [SecurityCritical]
1129  private EnumBuilder DefineEnumNoLock(string name, TypeAttributes visibility, Type underlyingType)
1130  {
1131  return new EnumBuilder(name, underlyingType, visibility, this);
1132  }
1133 
1142  public IResourceWriter DefineResource(string name, string description)
1143  {
1144  return DefineResource(name, description, ResourceAttributes.Public);
1145  }
1146 
1156  public IResourceWriter DefineResource(string name, string description, ResourceAttributes attribute)
1157  {
1158  lock (SyncRoot)
1159  {
1160  return DefineResourceNoLock(name, description, attribute);
1161  }
1162  }
1163 
1164  private IResourceWriter DefineResourceNoLock(string name, string description, ResourceAttributes attribute)
1165  {
1166  if (IsTransient())
1167  {
1168  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadResourceContainer"));
1169  }
1170  if (name == null)
1171  {
1172  throw new ArgumentNullException("name");
1173  }
1174  if (name.Length == 0)
1175  {
1176  throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
1177  }
1178  if (m_assemblyBuilder.IsPersistable())
1179  {
1180  m_assemblyBuilder.m_assemblyData.CheckResNameConflict(name);
1181  MemoryStream memoryStream = new MemoryStream();
1182  ResourceWriter resourceWriter = new ResourceWriter(memoryStream);
1183  ResWriterData resWriterData = new ResWriterData(resourceWriter, memoryStream, name, string.Empty, string.Empty, attribute);
1184  resWriterData.m_nextResWriter = m_moduleData.m_embeddedRes;
1185  m_moduleData.m_embeddedRes = resWriterData;
1186  return resourceWriter;
1187  }
1188  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadResourceContainer"));
1189  }
1190 
1201  public void DefineManifestResource(string name, Stream stream, ResourceAttributes attribute)
1202  {
1203  if (name == null)
1204  {
1205  throw new ArgumentNullException("name");
1206  }
1207  if (stream == null)
1208  {
1209  throw new ArgumentNullException("stream");
1210  }
1211  lock (SyncRoot)
1212  {
1213  DefineManifestResourceNoLock(name, stream, attribute);
1214  }
1215  }
1216 
1217  private void DefineManifestResourceNoLock(string name, Stream stream, ResourceAttributes attribute)
1218  {
1219  if (IsTransient())
1220  {
1221  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadResourceContainer"));
1222  }
1223  if (name == null)
1224  {
1225  throw new ArgumentNullException("name");
1226  }
1227  if (name.Length == 0)
1228  {
1229  throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
1230  }
1231  if (m_assemblyBuilder.IsPersistable())
1232  {
1233  m_assemblyBuilder.m_assemblyData.CheckResNameConflict(name);
1234  ResWriterData resWriterData = new ResWriterData(null, stream, name, string.Empty, string.Empty, attribute);
1235  resWriterData.m_nextResWriter = m_moduleData.m_embeddedRes;
1236  m_moduleData.m_embeddedRes = resWriterData;
1237  return;
1238  }
1239  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadResourceContainer"));
1240  }
1241 
1247  public void DefineUnmanagedResource(byte[] resource)
1248  {
1249  lock (SyncRoot)
1250  {
1251  DefineUnmanagedResourceInternalNoLock(resource);
1252  }
1253  }
1254 
1255  internal void DefineUnmanagedResourceInternalNoLock(byte[] resource)
1256  {
1257  if (resource == null)
1258  {
1259  throw new ArgumentNullException("resource");
1260  }
1261  if (m_moduleData.m_strResourceFileName != null || m_moduleData.m_resourceBytes != null)
1262  {
1263  throw new ArgumentException(Environment.GetResourceString("Argument_NativeResourceAlreadyDefined"));
1264  }
1265  m_moduleData.m_resourceBytes = new byte[resource.Length];
1266  Array.Copy(resource, m_moduleData.m_resourceBytes, resource.Length);
1267  }
1268 
1278  [SecuritySafeCritical]
1279  public void DefineUnmanagedResource(string resourceFileName)
1280  {
1281  lock (SyncRoot)
1282  {
1283  DefineUnmanagedResourceFileInternalNoLock(resourceFileName);
1284  }
1285  }
1286 
1287  [SecurityCritical]
1288  internal void DefineUnmanagedResourceFileInternalNoLock(string resourceFileName)
1289  {
1290  if (resourceFileName == null)
1291  {
1292  throw new ArgumentNullException("resourceFileName");
1293  }
1294  if (m_moduleData.m_resourceBytes != null || m_moduleData.m_strResourceFileName != null)
1295  {
1296  throw new ArgumentException(Environment.GetResourceString("Argument_NativeResourceAlreadyDefined"));
1297  }
1298  string text = Path.UnsafeGetFullPath(resourceFileName);
1300  new EnvironmentPermission(PermissionState.Unrestricted).Assert();
1301  try
1302  {
1303  if (!File.UnsafeExists(resourceFileName))
1304  {
1305  throw new FileNotFoundException(Environment.GetResourceString("IO.FileNotFound_FileName", resourceFileName), resourceFileName);
1306  }
1307  }
1308  finally
1309  {
1311  }
1312  m_moduleData.m_strResourceFileName = text;
1313  }
1314 
1326  public MethodBuilder DefineGlobalMethod(string name, MethodAttributes attributes, Type returnType, Type[] parameterTypes)
1327  {
1328  return DefineGlobalMethod(name, attributes, CallingConventions.Standard, returnType, parameterTypes);
1329  }
1330 
1343  public MethodBuilder DefineGlobalMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
1344  {
1345  return DefineGlobalMethod(name, attributes, callingConvention, returnType, null, null, parameterTypes, null, null);
1346  }
1347 
1363  public MethodBuilder DefineGlobalMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] requiredReturnTypeCustomModifiers, Type[] optionalReturnTypeCustomModifiers, Type[] parameterTypes, Type[][] requiredParameterTypeCustomModifiers, Type[][] optionalParameterTypeCustomModifiers)
1364  {
1365  lock (SyncRoot)
1366  {
1367  return DefineGlobalMethodNoLock(name, attributes, callingConvention, returnType, requiredReturnTypeCustomModifiers, optionalReturnTypeCustomModifiers, parameterTypes, requiredParameterTypeCustomModifiers, optionalParameterTypeCustomModifiers);
1368  }
1369  }
1370 
1371  private MethodBuilder DefineGlobalMethodNoLock(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] requiredReturnTypeCustomModifiers, Type[] optionalReturnTypeCustomModifiers, Type[] parameterTypes, Type[][] requiredParameterTypeCustomModifiers, Type[][] optionalParameterTypeCustomModifiers)
1372  {
1373  if (m_moduleData.m_fGlobalBeenCreated)
1374  {
1375  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_GlobalsHaveBeenCreated"));
1376  }
1377  if (name == null)
1378  {
1379  throw new ArgumentNullException("name");
1380  }
1381  if (name.Length == 0)
1382  {
1383  throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
1384  }
1385  if ((attributes & MethodAttributes.Static) == MethodAttributes.PrivateScope)
1386  {
1387  throw new ArgumentException(Environment.GetResourceString("Argument_GlobalFunctionHasToBeStatic"));
1388  }
1389  CheckContext(returnType);
1390  CheckContext(requiredReturnTypeCustomModifiers, optionalReturnTypeCustomModifiers, parameterTypes);
1391  CheckContext(requiredParameterTypeCustomModifiers);
1392  CheckContext(optionalParameterTypeCustomModifiers);
1393  m_moduleData.m_fHasGlobal = true;
1394  return m_moduleData.m_globalTypeBuilder.DefineMethod(name, attributes, callingConvention, returnType, requiredReturnTypeCustomModifiers, optionalReturnTypeCustomModifiers, parameterTypes, requiredParameterTypeCustomModifiers, optionalParameterTypeCustomModifiers);
1395  }
1396 
1411  public MethodBuilder DefinePInvokeMethod(string name, string dllName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet)
1412  {
1413  return DefinePInvokeMethod(name, dllName, name, attributes, callingConvention, returnType, parameterTypes, nativeCallConv, nativeCharSet);
1414  }
1415 
1431  public MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet)
1432  {
1433  lock (SyncRoot)
1434  {
1435  return DefinePInvokeMethodNoLock(name, dllName, entryName, attributes, callingConvention, returnType, parameterTypes, nativeCallConv, nativeCharSet);
1436  }
1437  }
1438 
1439  private MethodBuilder DefinePInvokeMethodNoLock(string name, string dllName, string entryName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet)
1440  {
1441  if ((attributes & MethodAttributes.Static) == MethodAttributes.PrivateScope)
1442  {
1443  throw new ArgumentException(Environment.GetResourceString("Argument_GlobalFunctionHasToBeStatic"));
1444  }
1445  CheckContext(returnType);
1446  CheckContext(parameterTypes);
1447  m_moduleData.m_fHasGlobal = true;
1448  return m_moduleData.m_globalTypeBuilder.DefinePInvokeMethod(name, dllName, entryName, attributes, callingConvention, returnType, parameterTypes, nativeCallConv, nativeCharSet);
1449  }
1450 
1454  {
1455  lock (SyncRoot)
1456  {
1457  CreateGlobalFunctionsNoLock();
1458  }
1459  }
1460 
1461  private void CreateGlobalFunctionsNoLock()
1462  {
1463  if (m_moduleData.m_fGlobalBeenCreated)
1464  {
1465  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotADebugModule"));
1466  }
1467  m_moduleData.m_globalTypeBuilder.CreateType();
1468  m_moduleData.m_fGlobalBeenCreated = true;
1469  }
1470 
1481  public FieldBuilder DefineInitializedData(string name, byte[] data, FieldAttributes attributes)
1482  {
1483  lock (SyncRoot)
1484  {
1485  return DefineInitializedDataNoLock(name, data, attributes);
1486  }
1487  }
1488 
1489  private FieldBuilder DefineInitializedDataNoLock(string name, byte[] data, FieldAttributes attributes)
1490  {
1491  if (m_moduleData.m_fGlobalBeenCreated)
1492  {
1493  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_GlobalsHaveBeenCreated"));
1494  }
1495  m_moduleData.m_fHasGlobal = true;
1496  return m_moduleData.m_globalTypeBuilder.DefineInitializedData(name, data, attributes);
1497  }
1498 
1510  public FieldBuilder DefineUninitializedData(string name, int size, FieldAttributes attributes)
1511  {
1512  lock (SyncRoot)
1513  {
1514  return DefineUninitializedDataNoLock(name, size, attributes);
1515  }
1516  }
1517 
1518  private FieldBuilder DefineUninitializedDataNoLock(string name, int size, FieldAttributes attributes)
1519  {
1520  if (m_moduleData.m_fGlobalBeenCreated)
1521  {
1522  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_GlobalsHaveBeenCreated"));
1523  }
1524  m_moduleData.m_fHasGlobal = true;
1525  return m_moduleData.m_globalTypeBuilder.DefineUninitializedData(name, size, attributes);
1526  }
1527 
1528  [SecurityCritical]
1529  internal TypeToken GetTypeTokenInternal(Type type)
1530  {
1531  return GetTypeTokenInternal(type, getGenericDefinition: false);
1532  }
1533 
1534  [SecurityCritical]
1535  private TypeToken GetTypeTokenInternal(Type type, bool getGenericDefinition)
1536  {
1537  lock (SyncRoot)
1538  {
1539  return GetTypeTokenWorkerNoLock(type, getGenericDefinition);
1540  }
1541  }
1542 
1551  [SecuritySafeCritical]
1553  {
1554  return GetTypeTokenInternal(type, getGenericDefinition: true);
1555  }
1556 
1557  [SecurityCritical]
1558  private TypeToken GetTypeTokenWorkerNoLock(Type type, bool getGenericDefinition)
1559  {
1560  if (type == null)
1561  {
1562  throw new ArgumentNullException("type");
1563  }
1564  CheckContext(type);
1565  if (type.IsByRef)
1566  {
1567  throw new ArgumentException(Environment.GetResourceString("Argument_CannotGetTypeTokenForByRef"));
1568  }
1569  if ((type.IsGenericType && (!type.IsGenericTypeDefinition || !getGenericDefinition)) || type.IsGenericParameter || type.IsArray || type.IsPointer)
1570  {
1571  int length;
1572  byte[] signature = SignatureHelper.GetTypeSigToken(this, type).InternalGetSignature(out length);
1573  return new TypeToken(GetTokenFromTypeSpec(signature, length));
1574  }
1575  Module module = type.Module;
1576  if (module.Equals(this))
1577  {
1578  TypeBuilder typeBuilder = null;
1579  GenericTypeParameterBuilder genericTypeParameterBuilder = null;
1580  EnumBuilder enumBuilder = type as EnumBuilder;
1581  typeBuilder = ((!(enumBuilder != null)) ? (type as TypeBuilder) : enumBuilder.m_typeBuilder);
1582  if (typeBuilder != null)
1583  {
1584  return typeBuilder.TypeToken;
1585  }
1586  if ((genericTypeParameterBuilder = (type as GenericTypeParameterBuilder)) != null)
1587  {
1588  return new TypeToken(genericTypeParameterBuilder.MetadataTokenInternal);
1589  }
1590  return new TypeToken(GetTypeRefNested(type, this, string.Empty));
1591  }
1592  ModuleBuilder moduleBuilder = module as ModuleBuilder;
1593  bool flag = (moduleBuilder != null) ? moduleBuilder.IsTransient() : ((RuntimeModule)module).IsTransientInternal();
1594  if (!IsTransient() && flag)
1595  {
1596  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadTransientModuleReference"));
1597  }
1598  string strRefedModuleFileName = string.Empty;
1599  if (module.Assembly.Equals(Assembly))
1600  {
1601  if (moduleBuilder == null)
1602  {
1603  moduleBuilder = ContainingAssemblyBuilder.GetModuleBuilder((InternalModuleBuilder)module);
1604  }
1605  strRefedModuleFileName = moduleBuilder.m_moduleData.m_strFileName;
1606  }
1607  return new TypeToken(GetTypeRefNested(type, module, strRefedModuleFileName));
1608  }
1609 
1619  public TypeToken GetTypeToken(string name)
1620  {
1621  return GetTypeToken(InternalModule.GetType(name, throwOnError: false, ignoreCase: true));
1622  }
1623 
1630  [SecuritySafeCritical]
1632  {
1633  lock (SyncRoot)
1634  {
1635  return GetMethodTokenNoLock(method, getGenericTypeDefinition: true);
1636  }
1637  }
1638 
1639  [SecurityCritical]
1640  internal MethodToken GetMethodTokenInternal(MethodInfo method)
1641  {
1642  lock (SyncRoot)
1643  {
1644  return GetMethodTokenNoLock(method, getGenericTypeDefinition: false);
1645  }
1646  }
1647 
1648  [SecurityCritical]
1649  private MethodToken GetMethodTokenNoLock(MethodInfo method, bool getGenericTypeDefinition)
1650  {
1651  if (method == null)
1652  {
1653  throw new ArgumentNullException("method");
1654  }
1655  int num = 0;
1656  SymbolMethod symbolMethod = null;
1657  MethodBuilder methodBuilder = null;
1658  if ((methodBuilder = (method as MethodBuilder)) != null)
1659  {
1660  int metadataTokenInternal = methodBuilder.MetadataTokenInternal;
1661  if (method.Module.Equals(this))
1662  {
1663  return new MethodToken(metadataTokenInternal);
1664  }
1665  if (method.DeclaringType == null)
1666  {
1667  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotImportGlobalFromDifferentModule"));
1668  }
1669  int tr = getGenericTypeDefinition ? GetTypeToken(method.DeclaringType).Token : GetTypeTokenInternal(method.DeclaringType).Token;
1670  num = GetMemberRef(method.DeclaringType.Module, tr, metadataTokenInternal);
1671  }
1672  else
1673  {
1674  if (method is MethodOnTypeBuilderInstantiation)
1675  {
1676  return new MethodToken(GetMemberRefToken(method, null));
1677  }
1678  if ((symbolMethod = (method as SymbolMethod)) != null)
1679  {
1680  if (symbolMethod.GetModule() == this)
1681  {
1682  return symbolMethod.GetToken();
1683  }
1684  return symbolMethod.GetToken(this);
1685  }
1686  Type declaringType = method.DeclaringType;
1687  if (declaringType == null)
1688  {
1689  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotImportGlobalFromDifferentModule"));
1690  }
1691  RuntimeMethodInfo runtimeMethodInfo = null;
1692  if (declaringType.IsArray)
1693  {
1694  ParameterInfo[] parameters = method.GetParameters();
1695  Type[] array = new Type[parameters.Length];
1696  for (int i = 0; i < parameters.Length; i++)
1697  {
1698  array[i] = parameters[i].ParameterType;
1699  }
1700  return GetArrayMethodToken(declaringType, method.Name, method.CallingConvention, method.ReturnType, array);
1701  }
1702  if ((runtimeMethodInfo = (method as RuntimeMethodInfo)) != null)
1703  {
1704  int tr = getGenericTypeDefinition ? GetTypeToken(method.DeclaringType).Token : GetTypeTokenInternal(method.DeclaringType).Token;
1705  num = GetMemberRefOfMethodInfo(tr, runtimeMethodInfo);
1706  }
1707  else
1708  {
1709  ParameterInfo[] parameters2 = method.GetParameters();
1710  Type[] array2 = new Type[parameters2.Length];
1711  Type[][] array3 = new Type[array2.Length][];
1712  Type[][] array4 = new Type[array2.Length][];
1713  for (int j = 0; j < parameters2.Length; j++)
1714  {
1715  array2[j] = parameters2[j].ParameterType;
1716  array3[j] = parameters2[j].GetRequiredCustomModifiers();
1717  array4[j] = parameters2[j].GetOptionalCustomModifiers();
1718  }
1719  int tr = getGenericTypeDefinition ? GetTypeToken(method.DeclaringType).Token : GetTypeTokenInternal(method.DeclaringType).Token;
1720  SignatureHelper methodSigHelper;
1721  try
1722  {
1723  methodSigHelper = SignatureHelper.GetMethodSigHelper(this, method.CallingConvention, method.ReturnType, method.ReturnParameter.GetRequiredCustomModifiers(), method.ReturnParameter.GetOptionalCustomModifiers(), array2, array3, array4);
1724  }
1725  catch (NotImplementedException)
1726  {
1727  methodSigHelper = SignatureHelper.GetMethodSigHelper(this, method.ReturnType, array2);
1728  }
1729  int length;
1730  byte[] signature = methodSigHelper.InternalGetSignature(out length);
1731  num = GetMemberRefFromSignature(tr, method.Name, signature, length);
1732  }
1733  }
1734  return new MethodToken(num);
1735  }
1736 
1743  [SecuritySafeCritical]
1744  public MethodToken GetConstructorToken(ConstructorInfo constructor, IEnumerable<Type> optionalParameterTypes)
1745  {
1746  if (constructor == null)
1747  {
1748  throw new ArgumentNullException("constructor");
1749  }
1750  lock (SyncRoot)
1751  {
1752  return new MethodToken(GetMethodTokenInternal(constructor, optionalParameterTypes, useMethodDef: false));
1753  }
1754  }
1755 
1763  [SecuritySafeCritical]
1764  public MethodToken GetMethodToken(MethodInfo method, IEnumerable<Type> optionalParameterTypes)
1765  {
1766  if (method == null)
1767  {
1768  throw new ArgumentNullException("method");
1769  }
1770  lock (SyncRoot)
1771  {
1772  return new MethodToken(GetMethodTokenInternal(method, optionalParameterTypes, useMethodDef: true));
1773  }
1774  }
1775 
1776  [SecurityCritical]
1777  internal int GetMethodTokenInternal(MethodBase method, IEnumerable<Type> optionalParameterTypes, bool useMethodDef)
1778  {
1779  int num = 0;
1780  MethodInfo methodInfo = method as MethodInfo;
1781  if (method.IsGenericMethod)
1782  {
1783  MethodInfo methodInfo2 = methodInfo;
1784  bool isGenericMethodDefinition = methodInfo.IsGenericMethodDefinition;
1785  if (!isGenericMethodDefinition)
1786  {
1787  methodInfo2 = methodInfo.GetGenericMethodDefinition();
1788  }
1789  num = ((Equals(methodInfo2.Module) && (!(methodInfo2.DeclaringType != null) || !methodInfo2.DeclaringType.IsGenericType)) ? GetMethodTokenInternal(methodInfo2).Token : GetMemberRefToken(methodInfo2, null));
1790  if (isGenericMethodDefinition && useMethodDef)
1791  {
1792  return num;
1793  }
1794  int length;
1795  byte[] signature = SignatureHelper.GetMethodSpecSigHelper(this, methodInfo.GetGenericArguments()).InternalGetSignature(out length);
1796  return TypeBuilder.DefineMethodSpec(GetNativeHandle(), num, signature, length);
1797  }
1798  if ((method.CallingConvention & CallingConventions.VarArgs) == (CallingConventions)0 && (method.DeclaringType == null || !method.DeclaringType.IsGenericType))
1799  {
1800  if (methodInfo != null)
1801  {
1802  return GetMethodTokenInternal(methodInfo).Token;
1803  }
1804  return GetConstructorToken(method as ConstructorInfo).Token;
1805  }
1806  return GetMemberRefToken(method, optionalParameterTypes);
1807  }
1808 
1820  [SecuritySafeCritical]
1821  public MethodToken GetArrayMethodToken(Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
1822  {
1823  lock (SyncRoot)
1824  {
1825  return GetArrayMethodTokenNoLock(arrayClass, methodName, callingConvention, returnType, parameterTypes);
1826  }
1827  }
1828 
1829  [SecurityCritical]
1830  private MethodToken GetArrayMethodTokenNoLock(Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
1831  {
1832  if (arrayClass == null)
1833  {
1834  throw new ArgumentNullException("arrayClass");
1835  }
1836  if (methodName == null)
1837  {
1838  throw new ArgumentNullException("methodName");
1839  }
1840  if (methodName.Length == 0)
1841  {
1842  throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "methodName");
1843  }
1844  if (!arrayClass.IsArray)
1845  {
1846  throw new ArgumentException(Environment.GetResourceString("Argument_HasToBeArrayClass"));
1847  }
1848  CheckContext(returnType, arrayClass);
1849  CheckContext(parameterTypes);
1850  SignatureHelper methodSigHelper = SignatureHelper.GetMethodSigHelper(this, callingConvention, returnType, null, null, parameterTypes, null, null);
1851  int length;
1852  byte[] signature = methodSigHelper.InternalGetSignature(out length);
1853  TypeToken typeTokenInternal = GetTypeTokenInternal(arrayClass);
1854  return new MethodToken(GetArrayMethodToken(GetNativeHandle(), typeTokenInternal.Token, methodName, signature, length));
1855  }
1856 
1868  [SecuritySafeCritical]
1869  public MethodInfo GetArrayMethod(Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
1870  {
1871  CheckContext(returnType, arrayClass);
1872  CheckContext(parameterTypes);
1873  MethodToken arrayMethodToken = GetArrayMethodToken(arrayClass, methodName, callingConvention, returnType, parameterTypes);
1874  return new SymbolMethod(this, arrayMethodToken, arrayClass, methodName, callingConvention, returnType, parameterTypes);
1875  }
1876 
1882  [SecuritySafeCritical]
1883  [ComVisible(true)]
1885  {
1886  return InternalGetConstructorToken(con, usingRef: false);
1887  }
1888 
1894  [SecuritySafeCritical]
1896  {
1897  lock (SyncRoot)
1898  {
1899  return GetFieldTokenNoLock(field);
1900  }
1901  }
1902 
1903  [SecurityCritical]
1904  private FieldToken GetFieldTokenNoLock(FieldInfo field)
1905  {
1906  if (field == null)
1907  {
1908  throw new ArgumentNullException("con");
1909  }
1910  int num = 0;
1911  FieldBuilder fieldBuilder = null;
1912  RuntimeFieldInfo runtimeFieldInfo = null;
1913  FieldOnTypeBuilderInstantiation fieldOnTypeBuilderInstantiation = null;
1914  if ((fieldBuilder = (field as FieldBuilder)) != null)
1915  {
1916  if (field.DeclaringType != null && field.DeclaringType.IsGenericType)
1917  {
1918  int length;
1919  byte[] signature = SignatureHelper.GetTypeSigToken(this, field.DeclaringType).InternalGetSignature(out length);
1920  int tokenFromTypeSpec = GetTokenFromTypeSpec(signature, length);
1921  num = GetMemberRef(this, tokenFromTypeSpec, fieldBuilder.GetToken().Token);
1922  }
1923  else
1924  {
1925  if (fieldBuilder.Module.Equals(this))
1926  {
1927  return fieldBuilder.GetToken();
1928  }
1929  if (field.DeclaringType == null)
1930  {
1931  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotImportGlobalFromDifferentModule"));
1932  }
1933  int tokenFromTypeSpec = GetTypeTokenInternal(field.DeclaringType).Token;
1934  num = GetMemberRef(field.ReflectedType.Module, tokenFromTypeSpec, fieldBuilder.GetToken().Token);
1935  }
1936  }
1937  else if ((runtimeFieldInfo = (field as RuntimeFieldInfo)) != null)
1938  {
1939  if (field.DeclaringType == null)
1940  {
1941  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotImportGlobalFromDifferentModule"));
1942  }
1943  if (field.DeclaringType != null && field.DeclaringType.IsGenericType)
1944  {
1945  int length2;
1946  byte[] signature2 = SignatureHelper.GetTypeSigToken(this, field.DeclaringType).InternalGetSignature(out length2);
1947  int tokenFromTypeSpec = GetTokenFromTypeSpec(signature2, length2);
1948  num = GetMemberRefOfFieldInfo(tokenFromTypeSpec, field.DeclaringType.GetTypeHandleInternal(), runtimeFieldInfo);
1949  }
1950  else
1951  {
1952  int tokenFromTypeSpec = GetTypeTokenInternal(field.DeclaringType).Token;
1953  num = GetMemberRefOfFieldInfo(tokenFromTypeSpec, field.DeclaringType.GetTypeHandleInternal(), runtimeFieldInfo);
1954  }
1955  }
1956  else if ((fieldOnTypeBuilderInstantiation = (field as FieldOnTypeBuilderInstantiation)) != null)
1957  {
1958  FieldInfo fieldInfo = fieldOnTypeBuilderInstantiation.FieldInfo;
1959  int length3;
1960  byte[] signature3 = SignatureHelper.GetTypeSigToken(this, field.DeclaringType).InternalGetSignature(out length3);
1961  int tokenFromTypeSpec = GetTokenFromTypeSpec(signature3, length3);
1962  num = GetMemberRef(fieldInfo.ReflectedType.Module, tokenFromTypeSpec, fieldOnTypeBuilderInstantiation.MetadataTokenInternal);
1963  }
1964  else
1965  {
1966  int tokenFromTypeSpec = GetTypeTokenInternal(field.ReflectedType).Token;
1967  SignatureHelper fieldSigHelper = SignatureHelper.GetFieldSigHelper(this);
1968  fieldSigHelper.AddArgument(field.FieldType, field.GetRequiredCustomModifiers(), field.GetOptionalCustomModifiers());
1969  int length4;
1970  byte[] signature4 = fieldSigHelper.InternalGetSignature(out length4);
1971  num = GetMemberRefFromSignature(tokenFromTypeSpec, field.Name, signature4, length4);
1972  }
1973  return new FieldToken(num, field.GetType());
1974  }
1975 
1981  [SecuritySafeCritical]
1982  public StringToken GetStringConstant(string str)
1983  {
1984  if (str == null)
1985  {
1986  throw new ArgumentNullException("str");
1987  }
1988  return new StringToken(GetStringConstant(GetNativeHandle(), str, str.Length));
1989  }
1990 
1996  [SecuritySafeCritical]
1998  {
1999  if (sigHelper == null)
2000  {
2001  throw new ArgumentNullException("sigHelper");
2002  }
2003  int length;
2004  byte[] signature = sigHelper.InternalGetSignature(out length);
2005  return new SignatureToken(TypeBuilder.GetTokenFromSig(GetNativeHandle(), signature, length), this);
2006  }
2007 
2014  [SecuritySafeCritical]
2015  public SignatureToken GetSignatureToken(byte[] sigBytes, int sigLength)
2016  {
2017  if (sigBytes == null)
2018  {
2019  throw new ArgumentNullException("sigBytes");
2020  }
2021  byte[] array = new byte[sigBytes.Length];
2022  Array.Copy(sigBytes, array, sigBytes.Length);
2023  return new SignatureToken(TypeBuilder.GetTokenFromSig(GetNativeHandle(), array, sigLength), this);
2024  }
2025 
2031  [SecuritySafeCritical]
2032  [ComVisible(true)]
2033  public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
2034  {
2035  if (con == null)
2036  {
2037  throw new ArgumentNullException("con");
2038  }
2039  if (binaryAttribute == null)
2040  {
2041  throw new ArgumentNullException("binaryAttribute");
2042  }
2043  TypeBuilder.DefineCustomAttribute(this, 1, GetConstructorToken(con).Token, binaryAttribute, toDisk: false, updateCompilerFlags: false);
2044  }
2045 
2050  [SecuritySafeCritical]
2051  public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
2052  {
2053  if (customBuilder == null)
2054  {
2055  throw new ArgumentNullException("customBuilder");
2056  }
2057  customBuilder.CreateCustomAttribute(this, 1);
2058  }
2059 
2063  {
2064  return m_iSymWriter;
2065  }
2066 
2076  public ISymbolDocumentWriter DefineDocument(string url, Guid language, Guid languageVendor, Guid documentType)
2077  {
2078  if (url == null)
2079  {
2080  throw new ArgumentNullException("url");
2081  }
2082  lock (SyncRoot)
2083  {
2084  return DefineDocumentNoLock(url, language, languageVendor, documentType);
2085  }
2086  }
2087 
2088  private ISymbolDocumentWriter DefineDocumentNoLock(string url, Guid language, Guid languageVendor, Guid documentType)
2089  {
2090  if (m_iSymWriter == null)
2091  {
2092  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotADebugModule"));
2093  }
2094  return m_iSymWriter.DefineDocument(url, language, languageVendor, documentType);
2095  }
2096 
2103  [SecuritySafeCritical]
2104  public void SetUserEntryPoint(MethodInfo entryPoint)
2105  {
2106  lock (SyncRoot)
2107  {
2108  SetUserEntryPointNoLock(entryPoint);
2109  }
2110  }
2111 
2112  [SecurityCritical]
2113  private void SetUserEntryPointNoLock(MethodInfo entryPoint)
2114  {
2115  if (entryPoint == null)
2116  {
2117  throw new ArgumentNullException("entryPoint");
2118  }
2119  if (m_iSymWriter == null)
2120  {
2121  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotADebugModule"));
2122  }
2123  if (entryPoint.DeclaringType != null)
2124  {
2125  if (!entryPoint.Module.Equals(this))
2126  {
2127  throw new InvalidOperationException(Environment.GetResourceString("Argument_NotInTheSameModuleBuilder"));
2128  }
2129  }
2130  else
2131  {
2132  MethodBuilder methodBuilder = entryPoint as MethodBuilder;
2133  if (methodBuilder != null && methodBuilder.GetModuleBuilder() != this)
2134  {
2135  throw new InvalidOperationException(Environment.GetResourceString("Argument_NotInTheSameModuleBuilder"));
2136  }
2137  }
2138  SymbolToken userEntryPoint = new SymbolToken(GetMethodTokenInternal(entryPoint).Token);
2139  m_iSymWriter.SetUserEntryPoint(userEntryPoint);
2140  }
2141 
2148  public void SetSymCustomAttribute(string name, byte[] data)
2149  {
2150  lock (SyncRoot)
2151  {
2152  SetSymCustomAttributeNoLock(name, data);
2153  }
2154  }
2155 
2156  private void SetSymCustomAttributeNoLock(string name, byte[] data)
2157  {
2158  if (m_iSymWriter == null)
2159  {
2160  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotADebugModule"));
2161  }
2162  }
2163 
2167  public bool IsTransient()
2168  {
2169  return InternalModule.IsTransientInternal();
2170  }
2171 
2175  void _ModuleBuilder.GetTypeInfoCount(out uint pcTInfo)
2176  {
2177  throw new NotImplementedException();
2178  }
2179 
2185  void _ModuleBuilder.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
2186  {
2187  throw new NotImplementedException();
2188  }
2189 
2197  void _ModuleBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
2198  {
2199  throw new NotImplementedException();
2200  }
2201 
2212  void _ModuleBuilder.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
2213  {
2214  throw new NotImplementedException();
2215  }
2216  }
2217 }
Obtains information about the attributes of a member and provides access to member metadata.
Definition: MemberInfo.cs:14
Exposes the T:System.Reflection.Emit.ModuleBuilder class to unmanaged code.
Performs reflection on a module.
Definition: Module.cs:17
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Definition: CultureInfo.cs:263
override Assembly Assembly
Gets the dynamic assembly that defined this instance of T:System.Reflection.Emit.ModuleBuilder.
MethodAttributes
Specifies flags for method attributes. These flags are defined in the corhdr.h file.
override bool IsDefined(Type attributeType, bool inherit)
Returns a value that indicates whether the specified attribute type has been applied to this module.
override object [] GetCustomAttributes(Type attributeType, bool inherit)
Returns all the custom attributes that have been applied to the current T:System.Reflection....
virtual bool IsGenericTypeDefinition
Gets a value indicating whether the current T:System.Type represents a generic type definition,...
Definition: Type.cs:579
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.
MethodBuilder DefineGlobalMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] requiredReturnTypeCustomModifiers, Type[] optionalReturnTypeCustomModifiers, Type[] parameterTypes, Type[][] requiredParameterTypeCustomModifiers, Type[][] optionalParameterTypeCustomModifiers)
Defines a global method with the specified name, attributes, calling convention, return type,...
The T:System.Diagnostics.SymbolStore.SymbolToken structure is an object representation of a token tha...
Definition: SymbolToken.cs:7
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
void SetUserEntryPoint(MethodInfo entryPoint)
Sets the user entry point.
FileIOPermissionAccess
Specifies the type of file access requested.
override string FullyQualifiedName
Gets a String representing the fully qualified name and path to this module.
Describes and represents an enumeration type.
Definition: EnumBuilder.cs:13
Provides the base functionality for writing resources to an output file or stream.
abstract Type FieldType
Gets the type of this field object.
Definition: FieldInfo.cs:34
FieldBuilder DefineUninitializedData(string name, int size, FieldAttributes attributes)
Defines an uninitialized data field in the .sdata section of the portable executable (PE) file.
virtual bool IsGenericParameter
Gets a value indicating whether the current T:System.Type represents a type parameter in the definiti...
Definition: Type.cs:605
abstract Type DeclaringType
Gets the class that declares this member.
Definition: MemberInfo.cs:36
int Count
Gets the number of elements contained in the T:System.Collections.Generic.List`1.
Definition: List.cs:296
override Type GetType(string className, bool ignoreCase)
Gets the named type defined in the module, optionally ignoring the case of the type name.
virtual MethodInfo GetGenericMethodDefinition()
Returns a T:System.Reflection.MethodInfo object that represents a generic method definition from whic...
Definition: MethodInfo.cs:120
static string Combine(string path1, string path2)
Combines two strings into a path.
Definition: Path.cs:1107
Discovers the attributes of a method and provides access to method metadata.
Definition: MethodInfo.cs:13
ISymbolDocumentWriter DefineDocument(string url, Guid language, Guid languageVendor, Guid documentType)
Defines a source document.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
void SetUserEntryPoint(SymbolToken entryMethod)
Identifies the user-defined method as the entry point for the current module.
override Guid ModuleVersionId
Gets a universally unique identifier (UUID) that can be used to distinguish between two versions of a...
MethodToken GetMethodToken(MethodInfo method, IEnumerable< Type > optionalParameterTypes)
Returns the token used to identify the method that has the specified attributes and parameter types w...
override int MDStreamVersion
Gets the metadata stream version.
Discovers the attributes of a class constructor and provides access to constructor metadata.
The MethodToken struct is an object representation of a token that represents a method.
Definition: MethodToken.cs:8
Discovers the attributes of a field and provides access to field metadata.
Definition: FieldInfo.cs:15
BindingFlags
Specifies flags that control binding and the way in which the search for members and types is conduct...
Definition: BindingFlags.cs:10
TypeBuilder DefineType(string name, TypeAttributes attr, Type parent, PackingSize packingSize, int typesize)
Constructs a TypeBuilder given the type name, attributes, the type that the defined type extends,...
Definition: __Canon.cs:3
virtual Type [] GetOptionalCustomModifiers()
Gets an array of types that identify the optional custom modifiers of the field.
Definition: FieldInfo.cs:299
ImageFileMachine
Identifies the platform targeted by an executable.
TypeBuilder DefineType(string name, TypeAttributes attr, Type parent, Type[] interfaces)
Constructs a TypeBuilder given the type name, attributes, the type that the defined type extends,...
Represents a token that represents a string.
Definition: StringToken.cs:8
CallingConvention
Specifies the calling convention required to call methods implemented in unmanaged code.
override byte [] ResolveSignature(int metadataToken)
Returns the signature blob identified by a metadata token.
virtual bool IsGenericType
Gets a value indicating whether the current type is a generic type.
Definition: Type.cs:566
Defines and represents a dynamic assembly.
SignatureToken GetSignatureToken(byte[] sigBytes, int sigLength)
Defines a token for the signature that has the specified character array and signature length.
Exposes the enumerator, which supports a simple iteration over a collection of a specified type....
Definition: IEnumerable.cs:9
Provides methods for building signatures.
override Type UnderlyingSystemType
Returns the underlying system type for this TypeBuilder.
Definition: TypeBuilder.cs:245
EnumBuilder DefineEnum(string name, TypeAttributes visibility, Type underlyingType)
Defines an enumeration type that is a value type with a single non-static field called value__ of th...
override bool Equals(object obj)
Returns a value that indicates whether this instance is equal to the specified object.
override object [] GetCustomAttributes(bool inherit)
Returns all the custom attributes that have been applied to the current T:System.Reflection....
void DefineManifestResource(string name, Stream stream, ResourceAttributes attribute)
Defines a binary large object (BLOB) that represents a manifest resource to be embedded in the dynami...
override Type ResolveType(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
Returns the type identified by the specified metadata token, in the context defined by the specified ...
SignatureToken GetSignatureToken(SignatureHelper sigHelper)
Defines a token for the signature that is defined by the specified T:System.Reflection....
Attaches a modifier to parameters so that binding can work with parameter signatures in which the typ...
MethodToken GetConstructorToken(ConstructorInfo constructor, IEnumerable< Type > optionalParameterTypes)
Returns the token used to identify the constructor that has the specified attributes and parameter ty...
Defines and represents a field. This class cannot be inherited.
Definition: FieldBuilder.cs:13
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...
override X509Certificate GetSignerCertificate()
Returns an T:System.Security.Cryptography.X509Certificates.X509Certificate object corresponding to th...
MethodBuilder DefineGlobalMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
Defines a global method with the specified name, attributes, calling convention, return type,...
MethodToken GetConstructorToken(ConstructorInfo con)
Returns the token used to identify the specified constructor within this module.
override string Name
A string that indicates that this is an in-memory module.
override int GetHashCode()
Returns the hash code for this instance.
CallingConventions
Defines the valid calling conventions for a method.
SecurityAction
Specifies the security actions that can be performed using declarative security.
ValueCollection Values
Gets a collection containing the values in the T:System.Collections.Generic.Dictionary`2.
Definition: Dictionary.cs:946
void DefineUnmanagedResource(byte[] resource)
Defines an unmanaged embedded resource given an opaque binary large object (BLOB) of bytes.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
Represents a globally unique identifier (GUID).To browse the .NET Framework source code for this type...
Definition: Guid.cs:14
bool IsArray
Gets a value that indicates whether the type is an array.
Definition: Type.cs:551
bool IsPointer
Gets a value indicating whether the T:System.Type is a pointer.
Definition: Type.cs:677
IResourceWriter DefineResource(string name, string description)
Defines the named managed embedded resource to be stored in this module.
KeyCollection Keys
Gets a collection containing the keys in the T:System.Collections.Generic.Dictionary`2.
Definition: Dictionary.cs:902
override bool Equals(object o)
Determines whether this module and the specified object are equal.
Definition: Module.cs:194
Creates a stream whose backing store is memory.To browse the .NET Framework source code for this type...
Definition: MemoryStream.cs:13
TypeBuilder DefineType(string name)
Constructs a TypeBuilder for a private type with the specified name in this module.
FieldBuilder DefineInitializedData(string name, byte[] data, FieldAttributes attributes)
Defines an initialized data field in the .sdata section of the portable executable (PE) file.
FieldToken GetFieldToken(FieldInfo field)
Returns the token used to identify the specified field within this module.
virtual bool IsGenericMethod
Gets a value indicating whether the method is generic.
Definition: MethodBase.cs:103
MethodBuilder DefineGlobalMethod(string name, MethodAttributes attributes, Type returnType, Type[] parameterTypes)
Defines a global method with the specified name, attributes, return type, and parameter types.
override Type GetType(string className)
Gets the named type defined in the module.
Defines and creates new instances of classes during run time.
Definition: TypeBuilder.cs:15
override MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
Returns the method or constructor identified by the specified metadata token, in the context defined ...
void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
Applies a custom attribute to this module by using a specified binary large object (BLOB) that repres...
TypeToken GetTypeToken(string name)
Returns the token used to identify the type with the specified name.
override Type [] GetTypes()
Returns all the classes defined within this module.
int Count
Gets the number of key/value pairs contained in the T:System.Collections.Generic.Dictionary`2.
Definition: Dictionary.cs:890
PackingSize
Specifies one of two factors that determine the memory alignment of fields when a type is marshaled.
Definition: PackingSize.cs:9
Defines and represents a module in a dynamic assembly.
MethodToken GetMethodToken(MethodInfo method)
Returns the token used to identify the specified method within this module.
virtual bool IsGenericMethodDefinition
Gets a value indicating whether the method is a generic method definition.
Definition: MethodBase.cs:77
FieldAttributes
Specifies flags that describe the attributes of a field.
ISymbolDocumentWriter DefineDocument(string url, Guid language, Guid languageVendor, Guid documentType)
Defines a document for source.
override string ResolveString(int metadataToken)
Returns the string identified by the specified metadata token.
void CreateGlobalFunctions()
Completes the global function definitions and global data definitions for this dynamic module.
override void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
Gets a pair of values indicating the nature of the code in a module and the platform targeted by the ...
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
Definition: Assembly.cs:22
Defines the underlying structure of all code access permissions.
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
TypeBuilder DefineType(string name, TypeAttributes attr, Type parent, int typesize)
Constructs a TypeBuilder given the type name, the attributes, the type that the defined type extends,...
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
Represents the Token returned by the metadata to represent a type.
Definition: TypeToken.cs:8
override FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
Returns the field identified by the specified metadata token, in the context defined by the specified...
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
virtual Type [] GetRequiredCustomModifiers()
Gets an array of types that identify the required custom modifiers of the property.
Definition: FieldInfo.cs:292
Provides information about methods and constructors.
Definition: MethodBase.cs:19
Type DeclaringType
Provides COM objects with version-independent access to the P:System.Reflection.MemberInfo....
Definition: _MethodInfo.cs:31
TypeBuilder DefineType(string name, TypeAttributes attr, Type parent)
Constructs a TypeBuilder given type name, its attributes, and the type that the defined type extends.
MethodImplOptions
Defines the details of how a method is implemented.
override Type GetType(string className, bool throwOnError, bool ignoreCase)
Gets the named type defined in the module, optionally ignoring the case of the type name....
CharSet
Dictates which character set marshaled strings should use.
Definition: CharSet.cs:7
abstract string Name
Gets the name of the current member.
Definition: MemberInfo.cs:27
virtual CallingConventions CallingConvention
Gets a value indicating the calling conventions for this method.
Definition: MethodBase.cs:64
TypeBuilder DefineType(string name, TypeAttributes attr)
Constructs a TypeBuilder given the type name and the type attributes.
Selects a member from a list of candidates, and performs type conversion from actual argument type to...
Definition: Binder.cs:10
TypeAttributes
Specifies type attributes.
Defines and represents a method (or constructor) on a dynamic class.
override Type [] GetGenericArguments()
Returns an array of T:System.Type objects that represent the type arguments of a generic method or th...
Definition: MethodInfo.cs:109
static void RevertAssert()
Causes any previous M:System.Security.CodeAccessPermission.Assert for the current frame to be removed...
Represents a collection of keys and values.To browse the .NET Framework source code for this type,...
Definition: Dictionary.cs:17
override MemberInfo ResolveMember(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
Returns the type or member identified by the specified metadata token, in the context defined by the ...
abstract Type ReflectedType
Gets the class object that was used to obtain this instance of MemberInfo.
Definition: MemberInfo.cs:45
override FieldInfo [] GetFields(BindingFlags bindingFlags)
Returns all fields defined in the .sdata region of the portable executable (PE) file that match the s...
IResourceWriter DefineResource(string name, string description, ResourceAttributes attribute)
Defines the named managed embedded resource with the given attributes that is to be stored in this mo...
Represents a collection of objects that can be individually accessed by index.
Definition: IList.cs:9
override MethodInfo [] GetMethods(BindingFlags bindingFlags)
Returns all the methods that have been defined at the module level for the current T:System....
The exception that is thrown when one of the arguments provided to a method is not valid.
Represents the Token returned by the metadata to represent a signature.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
The exception that is thrown when an attempt to access a file that does not exist on disk fails.
ResourceAttributes
Specifies the attributes for a manifest resource.
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
Writes resources in the system-default format to an output file or an output stream....
void GetTypeInfoCount(out uint pcTInfo)
Retrieves the number of type information interfaces that an object provides (either 0 or 1).
Represents a symbol writer for managed code.
Definition: ISymbolWriter.cs:8
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition: List.cs:14
override bool IsResource()
Gets a value indicating whether the object is a resource.
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
int Token
Returns the metadata token for this method.
Definition: MethodToken.cs:17
ISymbolWriter GetSymWriter()
Returns the symbol writer associated with this dynamic module.
virtual Module Module
Gets the module in which the type that declares the member represented by the current T:System....
Definition: MemberInfo.cs:78
Represents a document referenced by a symbol store.
PortableExecutableKinds
Identifies the nature of the code in an executable file.
MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet)
Defines a PInvoke method with the specified name, the name of the DLL in which the method is defined,...
override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
Returns the module-level method that matches the specified criteria.
MethodBuilder DefinePInvokeMethod(string name, string dllName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet)
Defines a PInvoke method with the specified name, the name of the DLL in which the method is defined,...
StringToken GetStringConstant(string str)
Returns the token of the given string in the module’s constant pool.
The exception that is thrown when a method call is invalid for the object's current state.
Provides static methods for the creation, copying, deletion, moving, and opening of a single file,...
Definition: File.cs:14
void Add(TKey key, TValue value)
Adds the specified key and value to the dictionary.
Definition: Dictionary.cs:1244
static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Gets the T:System.Type with the specified name, specifying whether to throw an exception if the type ...
Definition: Type.cs:853
Controls access to system and user environment variables. This class cannot be inherited.
ClassInterfaceType
Identifies the type of class interface that is generated for a class.
override string ScopeName
Gets a string that represents the name of the dynamic module.
override FieldInfo GetField(string name, BindingFlags bindingAttr)
Returns a module-level field, defined in the .sdata region of the portable executable (PE) file,...
int Token
Retrieves the metadata token for this class.
Definition: TypeToken.cs:17
void Assert()
Declares that the calling code can access the resource protected by a permission demand through the c...
void SetSymCustomAttribute(string name, byte[] data)
This method does nothing.
bool IsTransient()
Returns a value that indicates whether this dynamic module is transient.
TypeBuilder DefineType(string name, TypeAttributes attr, Type parent, PackingSize packsize)
Constructs a TypeBuilder given the type name, the attributes, the type that the defined type extends,...
abstract new Module Module
Gets the module (the DLL) in which the current T:System.Type is defined.
Definition: Type.cs:123
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
Controls the ability to access files and folders. This class cannot be inherited.
bool IsByRef
Gets a value indicating whether the T:System.Type is passed by reference.
Definition: Type.cs:664
ModuleHandle ModuleHandle
Gets a handle for the module.
Definition: Module.cs:148
override int MetadataToken
Gets a token that identifies the current dynamic module in metadata.
MethodToken GetArrayMethodToken(Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
Returns the token for the named method on an array class.
bool TryGetValue(TKey key, out TValue value)
Gets the value associated with the specified key.
Definition: Dictionary.cs:1624
bool IsCreated()
Returns a value that indicates whether the current dynamic type has been created.
Definition: TypeBuilder.cs:974
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.
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.
Performs operations on T:System.String instances that contain file or directory path information....
Definition: Path.cs:13
PEFileKinds
Specifies the type of the portable executable (PE) file.
Definition: PEFileKinds.cs:8
Provides methods that help you use X.509 v.3 certificates.
void SetCustomAttribute(CustomAttributeBuilder customBuilder)
Applies a custom attribute to this module by using a custom attribute builder.
MethodInfo GetArrayMethod(Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
Returns the named method on an array class.
override IList< CustomAttributeData > GetCustomAttributesData()
Returns information about the attributes that have been applied to the current T:System....
void DefineUnmanagedResource(string resourceFileName)
Defines an unmanaged resource given the name of Win32 resource file.
The FieldToken struct is an object representation of a token that represents a field.
Definition: FieldToken.cs:8
Provides a generic view of a sequence of bytes. This is an abstract class.To browse the ....
Definition: Stream.cs:16