internal TypeBuilder(ModuleBuilder module) { this.m_tdType = new System.Reflection.Emit.TypeToken(0x2000000); this.m_isHiddenGlobalType = true; this.m_module = module; this.m_listMethods = new List<MethodBuilder>(); this.m_lastTokenizedMethod = -1; }
private void Init(string fullname, TypeAttributes attr, Type parent, Type[] interfaces, System.Reflection.Module module, System.Reflection.Emit.PackingSize iPackingSize, int iTypeSize, TypeBuilder enclosingType) { if (fullname == null) { throw new ArgumentNullException("fullname"); } if (fullname.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "fullname"); } if (fullname[0] == '\0') { throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "fullname"); } if (fullname.Length > 0x3ff) { throw new ArgumentException(Environment.GetResourceString("Argument_TypeNameTooLong"), "fullname"); } this.m_bIsGenTypeDef = false; this.m_bIsGenParam = false; this.m_hasBeenCreated = false; this.m_runtimeType = null; this.m_isHiddenGlobalType = false; this.m_isHiddenType = false; this.m_module = (ModuleBuilder) module; this.m_DeclaringType = enclosingType; AssemblyBuilder containingAssemblyBuilder = this.m_module.ContainingAssemblyBuilder; this.m_underlyingSystemType = null; containingAssemblyBuilder.m_assemblyData.CheckTypeNameConflict(fullname, enclosingType); if ((enclosingType != null) && (((attr & TypeAttributes.NestedFamORAssem) == TypeAttributes.Public) || ((attr & TypeAttributes.NestedFamORAssem) == TypeAttributes.AnsiClass))) { throw new ArgumentException(Environment.GetResourceString("Argument_BadNestedTypeFlags"), "attr"); } int[] interfaceTokens = null; if (interfaces != null) { int num; for (num = 0; num < interfaces.Length; num++) { if (interfaces[num] == null) { throw new ArgumentNullException("interfaces"); } } interfaceTokens = new int[interfaces.Length + 1]; for (num = 0; num < interfaces.Length; num++) { interfaceTokens[num] = this.m_module.GetTypeTokenInternal(interfaces[num]).Token; } } int length = fullname.LastIndexOf('.'); switch (length) { case -1: case 0: this.m_strNameSpace = string.Empty; this.m_strName = fullname; break; default: this.m_strNameSpace = fullname.Substring(0, length); this.m_strName = fullname.Substring(length + 1); break; } this.VerifyTypeAttributes(attr); this.m_iAttr = attr; this.SetParent(parent); this.m_listMethods = new List<MethodBuilder>(); this.m_lastTokenizedMethod = -1; this.SetInterfaces(interfaces); this.m_constructorCount = 0; int tkParent = 0; if (this.m_typeParent != null) { tkParent = this.m_module.GetTypeTokenInternal(this.m_typeParent).Token; } int tkEnclosingType = 0; if (enclosingType != null) { tkEnclosingType = enclosingType.m_tdType.Token; } this.m_tdType = new System.Reflection.Emit.TypeToken(DefineType(this.m_module.GetNativeHandle(), fullname, tkParent, this.m_iAttr, tkEnclosingType, interfaceTokens)); this.m_iPackingSize = iPackingSize; this.m_iTypeSize = iTypeSize; if ((this.m_iPackingSize != System.Reflection.Emit.PackingSize.Unspecified) || (this.m_iTypeSize != 0)) { SetClassLayout(this.GetModuleBuilder().GetNativeHandle(), this.m_tdType.Token, this.m_iPackingSize, this.m_iTypeSize); } if (IsPublicComType(this)) { if (containingAssemblyBuilder.IsPersistable() && !this.m_module.IsTransient()) { containingAssemblyBuilder.m_assemblyData.AddPublicComType(this); } if (!this.m_module.Equals(containingAssemblyBuilder.ManifestModule)) { containingAssemblyBuilder.DefineExportedTypeInMemory(this, this.m_module.m_moduleData.FileToken, this.m_tdType.Token); } } }
private Type CreateTypeNoLock() { if (this.IsCreated()) { return this.m_runtimeType; } this.ThrowIfGeneric(); this.ThrowIfCreated(); if (this.m_typeInterfaces == null) { this.m_typeInterfaces = new List<Type>(); } int[] numArray = new int[this.m_typeInterfaces.Count]; for (int i = 0; i < this.m_typeInterfaces.Count; i++) { numArray[i] = this.m_module.GetTypeTokenInternal(this.m_typeInterfaces[i]).Token; } int tkParent = 0; if (this.m_typeParent != null) { tkParent = this.m_module.GetTypeTokenInternal(this.m_typeParent).Token; } if (this.IsGenericParameter) { int[] numArray2; if (this.m_typeParent != null) { numArray2 = new int[this.m_typeInterfaces.Count + 2]; numArray2[numArray2.Length - 2] = tkParent; } else { numArray2 = new int[this.m_typeInterfaces.Count + 1]; } for (int k = 0; k < this.m_typeInterfaces.Count; k++) { numArray2[k] = this.m_module.GetTypeTokenInternal(this.m_typeInterfaces[k]).Token; } int num4 = (this.m_declMeth == null) ? this.m_DeclaringType.m_tdType.Token : this.m_declMeth.GetToken().Token; this.m_tdType = new System.Reflection.Emit.TypeToken(DefineGenericParam(this.m_module.GetNativeHandle(), this.m_strName, num4, this.m_genParamAttributes, this.m_genParamPos, numArray2)); if (this.m_ca != null) { foreach (CustAttr attr in this.m_ca) { attr.Bake(this.m_module, this.MetadataTokenInternal); } } this.m_hasBeenCreated = true; return this; } if (((this.m_tdType.Token & 0xffffff) != 0) && ((tkParent & 0xffffff) != 0)) { SetParentType(this.m_module.GetNativeHandle(), this.m_tdType.Token, tkParent); } if (this.m_inst != null) { GenericTypeParameterBuilder[] inst = this.m_inst; for (int m = 0; m < inst.Length; m++) { Type type = inst[m]; if (type is GenericTypeParameterBuilder) { ((GenericTypeParameterBuilder) type).m_type.CreateType(); } } } if (((!this.m_isHiddenGlobalType && (this.m_constructorCount == 0)) && (((this.m_iAttr & TypeAttributes.ClassSemanticsMask) == TypeAttributes.AnsiClass) && !base.IsValueType)) && ((this.m_iAttr & (TypeAttributes.Sealed | TypeAttributes.Abstract)) != (TypeAttributes.Sealed | TypeAttributes.Abstract))) { this.DefineDefaultConstructor(MethodAttributes.Public); } int count = this.m_listMethods.Count; for (int j = 0; j < count; j++) { MethodBuilder builder = this.m_listMethods[j]; if (builder.IsGenericMethodDefinition) { builder.GetToken(); } MethodAttributes attributes = builder.Attributes; if (((builder.GetMethodImplementationFlags() & (MethodImplAttributes.PreserveSig | MethodImplAttributes.ManagedMask | MethodImplAttributes.CodeTypeMask)) == MethodImplAttributes.IL) && ((attributes & MethodAttributes.PinvokeImpl) == MethodAttributes.PrivateScope)) { int num5; int num8; byte[] signature = builder.GetLocalsSignature().InternalGetSignature(out num8); if (((attributes & MethodAttributes.Abstract) != MethodAttributes.PrivateScope) && ((this.m_iAttr & TypeAttributes.Abstract) == TypeAttributes.AnsiClass)) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadTypeAttributesNotAbstract")); } byte[] body = builder.GetBody(); if ((attributes & MethodAttributes.Abstract) != MethodAttributes.PrivateScope) { if (body != null) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadMethodBody")); } } else if ((body == null) || (body.Length == 0)) { if (builder.m_ilGenerator != null) { builder.CreateMethodBodyHelper(builder.GetILGenerator()); } body = builder.GetBody(); if (((body == null) || (body.Length == 0)) && !builder.m_canBeRuntimeImpl) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadEmptyMethodBody", new object[] { builder.Name })); } } if (builder.m_ilGenerator != null) { num5 = builder.m_ilGenerator.GetMaxStackSize() + builder.GetNumberOfExceptions(); } else { num5 = 0x10; } __ExceptionInstance[] exceptionInstances = builder.GetExceptionInstances(); int[] tokenFixups = builder.GetTokenFixups(); int[] rVAFixups = builder.GetRVAFixups(); SetMethodIL(this.m_module.GetNativeHandle(), builder.GetToken().Token, builder.InitLocals, body, (body != null) ? body.Length : 0, signature, num8, num5, exceptionInstances, (exceptionInstances != null) ? exceptionInstances.Length : 0, tokenFixups, (tokenFixups != null) ? tokenFixups.Length : 0, rVAFixups, (rVAFixups != null) ? rVAFixups.Length : 0); if (this.m_module.ContainingAssemblyBuilder.m_assemblyData.m_access == AssemblyBuilderAccess.Run) { builder.ReleaseBakedStructures(); } } } this.m_hasBeenCreated = true; RuntimeType o = null; TermCreateClass(this.m_module.GetNativeHandle(), this.m_tdType.Token, JitHelpers.GetObjectHandleOnStack<RuntimeType>(ref o)); if (this.m_isHiddenGlobalType) { return null; } this.m_runtimeType = o; if ((this.m_DeclaringType != null) && (this.m_DeclaringType.m_runtimeType != null)) { this.m_DeclaringType.m_runtimeType.InvalidateCachedNestedType(); } return o; }
public bool Equals(System.Reflection.Emit.TypeToken obj) { throw new PlatformNotSupportedException(); }