// Get the token for a method within this module. Returns // a member reference if the constructor is in another assembly. public MethodToken GetMethodToken(MethodInfo method) { if (method == null) { throw new ArgumentNullException("method"); } else if (method is MethodBuilder) { MethodBuilder mb = (method as MethodBuilder); if (mb.type.module == this) { return(mb.GetToken()); } } else if (method is ClrMethod) { lock (typeof(AssemblyBuilder)) { return(new MethodToken (TypeBuilder.ClrTypeImportMember (privateData, ((ClrMethod)method).ClrHandle))); } } throw new InvalidOperationException(_("Emit_CannotImportItem")); }
public MethodToken GetToken() { if (m_tkMethod.Token == 0) { if (m_link != null) { m_link.GetToken(); } int sigLength; byte[] sigBytes = GetMethodSignature().InternalGetSignature(out sigLength); m_tkMethod = new MethodToken(TypeBuilder.InternalDefineMethod( m_containingType.MetadataTokenInternal, m_strName, sigBytes, sigLength, Attributes, m_module)); if (m_inst != null) { foreach (GenericTypeParameterBuilder tb in m_inst) { if (!tb.m_type.IsCreated()) { tb.m_type.CreateType(); } } } TypeBuilder.InternalSetMethodImpl(m_module, MetadataTokenInternal, m_dwMethodImplFlags); } return(m_tkMethod); }
private void SetMethodSemantics(MethodBuilder mdBuilder, MethodSemanticsAttributes semantics) { if (mdBuilder == null) { throw new ArgumentNullException("mdBuilder"); } this.m_type.ThrowIfCreated(); TypeBuilder.DefineMethodSemantics(this.m_module.GetNativeHandle(), this.m_evToken.Token, semantics, mdBuilder.GetToken().Token); }
internal ConstructorBuilder(string name, MethodAttributes attributes, CallingConventions callingConvention, Type[]?parameterTypes, Type[][]?requiredCustomModifiers, Type[][]?optionalCustomModifiers, ModuleBuilder mod, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TypeBuilder type) { m_methodBuilder = new MethodBuilder(name, attributes, callingConvention, null, null, null, parameterTypes, requiredCustomModifiers, optionalCustomModifiers, mod, type); type.m_listMethods !.Add(m_methodBuilder); m_methodBuilder.GetMethodSignature().InternalGetSignature(out _); m_methodBuilder.GetToken(); }
/// <include file='doc\PropertyBuilder.uex' path='docs/doc[@for="PropertyBuilder.AddOtherMethod"]/*' /> public void AddOtherMethod(MethodBuilder mdBuilder) { if (mdBuilder == null) { throw new ArgumentNullException("mdBuilder"); } m_containingType.ThrowIfCreated(); TypeBuilder.InternalDefineMethodSemantics( m_module, m_prToken.Token, MethodSemanticsAttributes.Other, mdBuilder.GetToken().Token); }
/// <include file='doc\EventBuilder.uex' path='docs/doc[@for="EventBuilder.SetRaiseMethod"]/*' /> public void SetRaiseMethod(MethodBuilder mdBuilder) { if (mdBuilder == null) { throw new ArgumentNullException("mdBuilder"); } m_type.ThrowIfCreated(); TypeBuilder.InternalDefineMethodSemantics( m_module, m_evToken.Token, MethodSemanticsAttributes.Fire, mdBuilder.GetToken().Token); }
private void SetMethodSemantics(MethodBuilder mdBuilder, MethodSemanticsAttributes semantics) { if (mdBuilder == null) { throw new ArgumentNullException(nameof(mdBuilder)); } m_type.ThrowIfCreated(); TypeBuilder.DefineMethodSemantics( m_module.GetNativeHandle(), m_evToken.Token, semantics, mdBuilder.GetToken().Token); }
public void SetAddOnMethod(MethodBuilder mdBuilder) { if (mdBuilder == null) { throw new ArgumentNullException("mdBuilder"); } m_type.ThrowIfCreated(); TypeBuilder.InternalDefineMethodSemantics( m_module, m_evToken.Token, MethodSemanticsAttributes.AddOn, mdBuilder.GetToken().Token); }
[System.Security.SecurityCritical] // auto-generated private void SetMethodSemantics(MethodBuilder mdBuilder, MethodSemanticsAttributes semantics) { if (mdBuilder == null) { throw new ArgumentNullException(nameof(mdBuilder)); } Contract.EndContractBlock(); m_type.ThrowIfCreated(); TypeBuilder.DefineMethodSemantics( m_module.GetNativeHandle(), m_evToken.Token, semantics, mdBuilder.GetToken().Token); }
private void SetMethodSemantics(MethodBuilder mdBuilder, MethodSemanticsAttributes semantics) { if (mdBuilder == null) { throw new ArgumentNullException(nameof(mdBuilder)); } m_containingType.ThrowIfCreated(); ModuleBuilder module = m_moduleBuilder; TypeBuilder.DefineMethodSemantics( JitHelpers.GetQCallModuleOnStack(ref module), m_prToken.Token, semantics, mdBuilder.GetToken().Token); }
[System.Security.SecurityCritical] // auto-generated internal ConstructorBuilder(String name, MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers, ModuleBuilder mod, TypeBuilder type) { int sigLength; byte[] sigBytes; MethodToken token; m_methodBuilder = new MethodBuilder(name, attributes, callingConvention, null, null, null, parameterTypes, requiredCustomModifiers, optionalCustomModifiers, mod, type, false); type.m_listMethods.Add(m_methodBuilder); sigBytes = m_methodBuilder.GetMethodSignature().InternalGetSignature(out sigLength); token = m_methodBuilder.GetToken(); }
internal ConstructorBuilder(string name, MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers, ModuleBuilder mod, TypeBuilder type) { int sigLength; byte[] sigBytes; MethodToken token; m_methodBuilder = new MethodBuilder(name, attributes, callingConvention, null, null, null, parameterTypes, requiredCustomModifiers, optionalCustomModifiers, mod, type, false); type.m_listMethods.Add(m_methodBuilder); sigBytes = m_methodBuilder.GetMethodSignature().InternalGetSignature(out sigLength); token = m_methodBuilder.GetToken(); }
internal ParameterBuilder( MethodBuilder methodBuilder, int sequence, ParameterAttributes attributes, String strParamName) // can be NULL string { m_iPosition = sequence; m_strParamName = strParamName; m_methodBuilder = methodBuilder; m_strParamName = strParamName; m_attributes = attributes; m_pdToken = new ParameterToken(TypeBuilder.SetParamInfo( m_methodBuilder.GetModuleBuilder().GetNativeHandle(), m_methodBuilder.GetToken().Token, sequence, attributes, strParamName)); }
private void SetMethodSemantics(MethodBuilder mdBuilder, MethodSemanticsAttributes semantics) { if ((MethodInfo)mdBuilder == (MethodInfo)null) { throw new ArgumentNullException("mdBuilder"); } this.m_type.ThrowIfCreated(); TypeBuilder.DefineMethodSemantics(this.m_module.GetNativeHandle(), this.m_evToken.Token, semantics, mdBuilder.GetToken().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; }
public void AddOtherMethod(MethodBuilder mdBuilder) { if (mdBuilder == null) { throw new ArgumentNullException("mdBuilder"); } m_containingType.ThrowIfCreated(); TypeBuilder.InternalDefineMethodSemantics( m_module, m_prToken.Token, MethodSemanticsAttributes.Other, mdBuilder.GetToken().Token); }
[System.Security.SecurityCritical] // auto-generated internal ParameterBuilder( MethodBuilder methodBuilder, int sequence, ParameterAttributes attributes, String strParamName) // can be NULL string { m_iPosition = sequence; m_strParamName = strParamName; m_methodBuilder = methodBuilder; m_strParamName = strParamName; m_attributes = attributes; m_pdToken = new ParameterToken( TypeBuilder.SetParamInfo( m_methodBuilder.GetModuleBuilder().GetNativeHandle(), m_methodBuilder.GetToken().Token, sequence, attributes, strParamName)); }
public MethodToken GetToken() { return(m_methodBuilder.GetToken()); }
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; }
// Reflection.Emit is missing API to set all PInvoke flags (only some can be set via available APIs). private void SetPInvokeAttributes(MethodBuilder method, string dllName, string importName, Cci.PInvokeAttributes attributes) { if (s_lazyTypeBuilder_SetPInvokeData == null) { s_lazyTypeBuilder_SetPInvokeData = typeof(TypeBuilder).GetMethod("SetPInvokeData", BindingFlags.NonPublic | BindingFlags.Static); if (s_lazyTypeBuilder_SetPInvokeData == null) { throw new NotSupportedException("Ref.Emit limitation"); } } s_lazyTypeBuilder_SetPInvokeData.Invoke(null, new[] { RuntimeModule, dllName, importName, method.GetToken().Token, attributes }); }
[System.Security.SecurityCritical] // auto-generated private void SetMethodSemantics(MethodBuilder mdBuilder, MethodSemanticsAttributes semantics) { if (mdBuilder == null) { throw new ArgumentNullException(nameof(mdBuilder)); } m_containingType.ThrowIfCreated(); TypeBuilder.DefineMethodSemantics( m_moduleBuilder.GetNativeHandle(), m_prToken.Token, semantics, mdBuilder.GetToken().Token); }