// This is only called from TypeBuilder.CreateType after the method has been created internal void ReleaseBakedStructures() { if (!m_bIsBaked) { // We don't need to do anything here if we didn't baked the method body return; } m_ubBody = null; m_localSymInfo = null; m_mdMethodFixups = null; m_localSignature = null; m_exceptions = null; }
internal MethodBuilder(string name, MethodAttributes attributes, CallingConventions callingConvention, Type?returnType, Type[]?returnTypeRequiredCustomModifiers, Type[]?returnTypeOptionalCustomModifiers, Type[]?parameterTypes, Type[][]?parameterTypeRequiredCustomModifiers, Type[][]?parameterTypeOptionalCustomModifiers, ModuleBuilder mod, TypeBuilder type, bool bIsGlobalMethod) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (name.Length == 0) { throw new ArgumentException(SR.Argument_EmptyName, nameof(name)); } if (name[0] == '\0') { throw new ArgumentException(SR.Argument_IllegalName, nameof(name)); } if (mod == null) { throw new ArgumentNullException(nameof(mod)); } if (parameterTypes != null) { foreach (Type t in parameterTypes) { if (t == null) { throw new ArgumentNullException(nameof(parameterTypes)); } } } m_strName = name; m_module = mod; m_containingType = type; // //if (returnType == null) //{ // m_returnType = typeof(void); //} //else { m_returnType = returnType; } if ((attributes & MethodAttributes.Static) == 0) { // turn on the has this calling convention callingConvention = callingConvention | CallingConventions.HasThis; } else if ((attributes & MethodAttributes.Virtual) != 0) { // A method can't be both static and virtual throw new ArgumentException(SR.Arg_NoStaticVirtual); } #if !FEATURE_DEFAULT_INTERFACES if ((attributes & MethodAttributes.SpecialName) != MethodAttributes.SpecialName) { if ((type.Attributes & TypeAttributes.Interface) == TypeAttributes.Interface) { // methods on interface have to be abstract + virtual except special name methods such as type initializer if ((attributes & (MethodAttributes.Abstract | MethodAttributes.Virtual)) != (MethodAttributes.Abstract | MethodAttributes.Virtual) && (attributes & MethodAttributes.Static) == 0) { throw new ArgumentException(SR.Argument_BadAttributeOnInterfaceMethod); } } } #endif m_callingConvention = callingConvention; if (parameterTypes != null) { m_parameterTypes = new Type[parameterTypes.Length]; Array.Copy(parameterTypes, 0, m_parameterTypes, 0, parameterTypes.Length); } else { m_parameterTypes = null; } m_returnTypeRequiredCustomModifiers = returnTypeRequiredCustomModifiers; m_returnTypeOptionalCustomModifiers = returnTypeOptionalCustomModifiers; m_parameterTypeRequiredCustomModifiers = parameterTypeRequiredCustomModifiers; m_parameterTypeOptionalCustomModifiers = parameterTypeOptionalCustomModifiers; // m_signature = SignatureHelper.GetMethodSigHelper(mod, callingConvention, // returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers, // parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers); m_iAttributes = attributes; m_bIsGlobalMethod = bIsGlobalMethod; m_bIsBaked = false; m_fInitLocals = true; m_localSymInfo = new LocalSymInfo(); m_ubBody = null; m_ilGenerator = null; // Default is managed IL. Manged IL has bit flag 0x0020 set off m_dwMethodImplFlags = MethodImplAttributes.IL; }
internal MethodBuilder(string name, MethodAttributes attributes, CallingConventions callingConvention, Type?returnType, Type[]?returnTypeRequiredCustomModifiers, Type[]?returnTypeOptionalCustomModifiers, Type[]?parameterTypes, Type[][]?parameterTypeRequiredCustomModifiers, Type[][]?parameterTypeOptionalCustomModifiers, ModuleBuilder mod, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TypeBuilder type) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (name.Length == 0) { throw new ArgumentException(SR.Argument_EmptyName, nameof(name)); } if (name[0] == '\0') { throw new ArgumentException(SR.Argument_IllegalName, nameof(name)); } if (mod == null) { throw new ArgumentNullException(nameof(mod)); } if (parameterTypes != null) { foreach (Type t in parameterTypes) { if (t == null) { throw new ArgumentNullException(nameof(parameterTypes)); } } } m_strName = name; m_module = mod; m_containingType = type; m_returnType = returnType ?? typeof(void); if ((attributes & MethodAttributes.Static) == 0) { // turn on the has this calling convention callingConvention |= CallingConventions.HasThis; } else if ((attributes & MethodAttributes.Virtual) != 0) { // On an interface, the rule is slighlty different if (((attributes & MethodAttributes.Abstract) == 0)) { throw new ArgumentException(SR.Arg_NoStaticVirtual); } } m_callingConvention = callingConvention; if (parameterTypes != null) { m_parameterTypes = new Type[parameterTypes.Length]; Array.Copy(parameterTypes, m_parameterTypes, parameterTypes.Length); } else { m_parameterTypes = null; } m_returnTypeRequiredCustomModifiers = returnTypeRequiredCustomModifiers; m_returnTypeOptionalCustomModifiers = returnTypeOptionalCustomModifiers; m_parameterTypeRequiredCustomModifiers = parameterTypeRequiredCustomModifiers; m_parameterTypeOptionalCustomModifiers = parameterTypeOptionalCustomModifiers; // m_signature = SignatureHelper.GetMethodSigHelper(mod, callingConvention, // returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers, // parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers); m_iAttributes = attributes; m_bIsBaked = false; m_fInitLocals = true; m_localSymInfo = new LocalSymInfo(); m_ubBody = null; m_ilGenerator = null; // Default is managed IL. Manged IL has bit flag 0x0020 set off m_dwMethodImplFlags = MethodImplAttributes.IL; }