/********************************************** * Constructs a ConstructorBuilder. * @internalonly **********************************************/ internal ConstructorBuilder( String name, MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes, Module mod, TypeBuilder type) { int sigLength; byte[] sigBytes; MethodToken token; m_methodBuilder = new MethodBuilder(name, attributes, callingConvention, null, parameterTypes, mod, type, false); type.m_listMethods.Add(m_methodBuilder); sigBytes = m_methodBuilder.GetMethodSignature().InternalGetSignature(out sigLength); token = TypeBuilder.InternalDefineMethod(type.TypeToken, name, sigBytes, sigLength, attributes, mod); m_ReturnILGen = true; m_methodBuilder.SetToken(token); }
[System.Security.SecurityCritical] // auto-generated private MethodBuilder DefinePInvokeMethodHelperNoLock( String name, String dllName, String importName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers, CallingConvention nativeCallConv, CharSet nativeCharSet) { if (name == null) throw new ArgumentNullException("name"); if (name.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); if (dllName == null) throw new ArgumentNullException("dllName"); if (dllName.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "dllName"); if (importName == null) throw new ArgumentNullException("importName"); if (importName.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "importName"); if ((attributes & MethodAttributes.Abstract) != 0) throw new ArgumentException(Environment.GetResourceString("Argument_BadPInvokeMethod")); Contract.EndContractBlock(); if ((m_iAttr & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface) throw new ArgumentException(Environment.GetResourceString("Argument_BadPInvokeOnInterface")); ThrowIfCreated(); attributes = attributes | MethodAttributes.PinvokeImpl; MethodBuilder method = new MethodBuilder(name, attributes, callingConvention, returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers, parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers, m_module, this, false); //The signature grabbing code has to be up here or the signature won't be finished //and our equals check won't work. int sigLength; byte[] sigBytes = method.GetMethodSignature().InternalGetSignature(out sigLength); if (m_listMethods.Contains(method)) { throw new ArgumentException(Environment.GetResourceString("Argument_MethodRedefined")); } m_listMethods.Add(method); MethodToken token = method.GetToken(); int linkFlags = 0; switch(nativeCallConv) { case CallingConvention.Winapi: linkFlags =(int)PInvokeMap.CallConvWinapi; break; case CallingConvention.Cdecl: linkFlags =(int)PInvokeMap.CallConvCdecl; break; case CallingConvention.StdCall: linkFlags =(int)PInvokeMap.CallConvStdcall; break; case CallingConvention.ThisCall: linkFlags =(int)PInvokeMap.CallConvThiscall; break; case CallingConvention.FastCall: linkFlags =(int)PInvokeMap.CallConvFastcall; break; } switch(nativeCharSet) { case CharSet.None: linkFlags |=(int)PInvokeMap.CharSetNotSpec; break; case CharSet.Ansi: linkFlags |=(int)PInvokeMap.CharSetAnsi; break; case CharSet.Unicode: linkFlags |=(int)PInvokeMap.CharSetUnicode; break; case CharSet.Auto: linkFlags |=(int)PInvokeMap.CharSetAuto; break; } SetPInvokeData(m_module.GetNativeHandle(), dllName, importName, token.Token, linkFlags); method.SetToken(token); return method; }
private MethodBuilder DefinePInvokeMethodHelperNoLock(string name, string dllName, string importName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers, CallingConvention nativeCallConv, CharSet nativeCharSet) { int num; if (name == null) { throw new ArgumentNullException("name"); } if (name.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); } if (dllName == null) { throw new ArgumentNullException("dllName"); } if (dllName.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "dllName"); } if (importName == null) { throw new ArgumentNullException("importName"); } if (importName.Length == 0) { throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "importName"); } if ((attributes & MethodAttributes.Abstract) != MethodAttributes.PrivateScope) { throw new ArgumentException(Environment.GetResourceString("Argument_BadPInvokeMethod")); } if ((this.m_iAttr & TypeAttributes.ClassSemanticsMask) == TypeAttributes.ClassSemanticsMask) { throw new ArgumentException(Environment.GetResourceString("Argument_BadPInvokeOnInterface")); } this.ThrowIfCreated(); attributes |= MethodAttributes.PinvokeImpl; MethodBuilder item = new MethodBuilder(name, attributes, callingConvention, returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers, parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers, this.m_module, this, false); item.GetMethodSignature().InternalGetSignature(out num); if (this.m_listMethods.Contains(item)) { throw new ArgumentException(Environment.GetResourceString("Argument_MethodRedefined")); } this.m_listMethods.Add(item); MethodToken token = item.GetToken(); int linkFlags = 0; switch (nativeCallConv) { case CallingConvention.Winapi: linkFlags = 0x100; break; case CallingConvention.Cdecl: linkFlags = 0x200; break; case CallingConvention.StdCall: linkFlags = 0x300; break; case CallingConvention.ThisCall: linkFlags = 0x400; break; case CallingConvention.FastCall: linkFlags = 0x500; break; } switch (nativeCharSet) { case CharSet.None: break; case CharSet.Ansi: linkFlags |= 2; break; case CharSet.Unicode: linkFlags |= 4; break; case CharSet.Auto: linkFlags |= 6; break; } SetPInvokeData(this.m_module.GetNativeHandle(), dllName, importName, token.Token, linkFlags); item.SetToken(token); return item; }
private MethodBuilder DefinePInvokeMethodHelper( String name, // name of the function of the dll entry String dllName, // dll containing the PInvoke method String importName, // the import entry's name MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, // The native calling convention. CharSet nativeCharSet) // Method's native character set. { try { Enter(); ThrowIfCreated(); if (name == null) throw new ArgumentNullException("name"); if (name.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); if (dllName == null) throw new ArgumentNullException("dllName"); if (dllName.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "dllName"); if (importName == null) throw new ArgumentNullException("importName"); if (importName.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "importName"); if ((m_iAttr & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface) throw new ArgumentException(Environment.GetResourceString("Argument_BadPInvokeOnInterface")); if ((attributes & MethodAttributes.Abstract) != 0) throw new ArgumentException(Environment.GetResourceString("Argument_BadPInvokeMethod")); attributes = attributes | MethodAttributes.PinvokeImpl; MethodBuilder method = new MethodBuilder(name, attributes, callingConvention, returnType, parameterTypes, m_module, this, false); //The signature grabbing code has to be up here or the signature won't be finished //and our equals check won't work. int sigLength; byte[] sigBytes = method.GetMethodSignature().InternalGetSignature(out sigLength); if (m_listMethods.Contains(method)) { throw new ArgumentException(Environment.GetResourceString("Argument_MethodRedefined")); } m_listMethods.Add(method); MethodToken token; token.m_method = InternalDefineMethod(m_tdType.Token, name, sigBytes, sigLength, attributes, m_module); int linkFlags = 0; switch (nativeCallConv) { case CallingConvention.Winapi: linkFlags = (int)PInvokeMap.CallConvWinapi; break; case CallingConvention.Cdecl: linkFlags = (int)PInvokeMap.CallConvCdecl; break; case CallingConvention.StdCall: linkFlags = (int)PInvokeMap.CallConvStdcall; break; case CallingConvention.ThisCall: linkFlags = (int)PInvokeMap.CallConvThiscall; break; case CallingConvention.FastCall: linkFlags = (int)PInvokeMap.CallConvFastcall; break; } switch (nativeCharSet) { case CharSet.None: linkFlags |= (int)PInvokeMap.CharSetNotSpec; break; case CharSet.Ansi: linkFlags |= (int)PInvokeMap.CharSetAnsi; break; case CharSet.Unicode: linkFlags |= (int)PInvokeMap.CharSetUnicode; break; case CharSet.Auto: linkFlags |= (int)PInvokeMap.CharSetAuto; break; } InternalSetPInvokeData(m_module, dllName, importName, token.Token, 0, linkFlags); method.SetToken(token); return method; } finally { Exit(); } }
/// <include file='doc\TypeBuilder.uex' path='docs/doc[@for="TypeBuilder.DefineMethod1"]/*' /> public MethodBuilder DefineMethod( String name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) { try { Enter(); BCLDebug.Log("DYNIL","## DYNIL LOGGING: TypeBuilder.DefineMethod( " + name + " )"); if (name == null) throw new ArgumentNullException("name"); if (name.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); ThrowIfCreated(); if (!m_isHiddenGlobalType) { if (((m_iAttr & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface) && (attributes & MethodAttributes.Abstract)==0) throw new ArgumentException(Environment.GetResourceString("Argument_BadAttributeOnInterfaceMethod")); } // pass in Method attributes MethodBuilder method = new MethodBuilder(name, attributes, callingConvention, returnType, parameterTypes, m_module, this, false); //The signature grabbing code has to be up here or the signature won't be finished //and our equals check won't work. int sigLength; byte[] sigBytes = method.GetMethodSignature().InternalGetSignature(out sigLength); if (!m_isHiddenGlobalType) { //If this method is declared to be a constructor, //increment our constructor count. if ((method.Attributes & MethodAttributes.SpecialName)!=0 && method.Name.Equals(ConstructorInfo.ConstructorName)) { m_constructorCount++; } } m_listMethods.Add(method); MethodToken token; token.m_method = InternalDefineMethod(m_tdType.Token, name, sigBytes, sigLength, method.Attributes, m_module); method.SetToken(token); return method; } finally { Exit(); } }
/********************************************** * Constructs a ConstructorBuilder. **********************************************/ internal ConstructorBuilder( String name, MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes, Module mod, TypeBuilder type) { int sigLength; byte[] sigBytes; MethodToken token; m_methodBuilder = new MethodBuilder(name, attributes, callingConvention, null, parameterTypes, mod, type, false); type.m_listMethods.Add(m_methodBuilder); sigBytes = m_methodBuilder.GetMethodSignature().InternalGetSignature(out sigLength); token.m_method = TypeBuilder.InternalDefineMethod(type.TypeToken.Token, name, sigBytes, sigLength, attributes, mod); m_ReturnILGen = true; m_methodBuilder.SetToken(token); }