public static GetMethodSigHelper ( System callingConvention, System returnType ) : System.Reflection.Emit.SignatureHelper | ||
callingConvention | System | |
returnType | System | |
return | System.Reflection.Emit.SignatureHelper |
internal SignatureHelper GetMethodSignature() { if (m_parameterTypes == null) { m_parameterTypes = EmptyArray <Type> .Value; } m_signature = SignatureHelper.GetMethodSigHelper(m_module, m_callingConvention, m_inst != null ? m_inst.Length : 0, m_returnType == null ? typeof(void) : m_returnType, m_returnTypeRequiredCustomModifiers, m_returnTypeOptionalCustomModifiers, m_parameterTypes, m_parameterTypeRequiredCustomModifiers, m_parameterTypeOptionalCustomModifiers); return(m_signature); }
public override void EmitCalli( OpCode opcode, CallingConvention unmanagedCallConv, Type?returnType, Type[]?parameterTypes ) { int stackchange = 0; int cParams = 0; int i; SignatureHelper sig; if (parameterTypes != null) { cParams = parameterTypes.Length; } sig = SignatureHelper.GetMethodSigHelper(unmanagedCallConv, returnType); if (parameterTypes != null) { for (i = 0; i < cParams; i++) { sig.AddArgument(parameterTypes[i]); } } // If there is a non-void return type, push one. if (returnType != typeof(void)) { stackchange++; } // Pop off arguments if any. if (parameterTypes != null) { stackchange -= cParams; } // Pop the native function pointer. stackchange--; UpdateStackSize(OpCodes.Calli, stackchange); EnsureCapacity(7); Emit(OpCodes.Calli); int token = GetTokenForSig(sig.GetSignature(true)); PutInteger4(token); }
public override void EmitCalli(OpCode opcode, CallingConvention unmanagedCallConv, Type returnType, Type[] parameterTypes) { int stackchange = 0; int cParams = 0; int i; SignatureHelper sig; // The opcode passed in must be the calli instruction. BCLDebug.Assert(opcode.Equals(OpCodes.Calli), "Unexpected opcode passed to EmitCalli."); if (parameterTypes != null) { cParams = parameterTypes.Length; } sig = SignatureHelper.GetMethodSigHelper(unmanagedCallConv, returnType); if (parameterTypes != null) { for (i = 0; i < cParams; i++) { sig.AddArgument(parameterTypes[i]); } } // If there is a non-void return type, push one. if (returnType != typeof(void)) { stackchange++; } // Pop off arguments if any. if (parameterTypes != null) { stackchange -= cParams; } // Pop the native function pointer. stackchange--; UpdateStackSize(opcode, stackchange); EnsureCapacity(7); Emit(OpCodes.Calli); int token = AddSignature(sig.GetSignature(true)); m_length = PutInteger4(token, m_length, m_ILStream); }
internal SymbolMethod( ModuleBuilder mod, int token, Type arrayClass, string methodName, CallingConventions callingConvention, Type?returnType, Type[]?parameterTypes ) { // This is a kind of MethodInfo to represent methods for array type of unbaked type // Another way to look at this class is as a glorified MethodToken wrapper. At the time of this comment // this class is only constructed inside ModuleBuilder.GetArrayMethod and the only interesting thing // passed into it is this MethodToken. The MethodToken was forged using a TypeSpec for an Array type and // the name of the method on Array. // As none of the methods on Array have CustomModifiers their is no need to pass those around in here. m_token = token; // The ParameterTypes are also a bit interesting in that they may be unbaked TypeBuilders. m_returnType = returnType ?? typeof(void); if (parameterTypes != null) { m_parameterTypes = new Type[parameterTypes.Length]; Array.Copy(parameterTypes, m_parameterTypes, parameterTypes.Length); } else { m_parameterTypes = Type.EmptyTypes; } m_module = mod; m_containingType = arrayClass; m_name = methodName; m_callingConvention = callingConvention; // Validate signature SignatureHelper.GetMethodSigHelper( mod, callingConvention, returnType, null, null, parameterTypes, null, null ); }
internal SignatureHelper GetMethodSignature() { m_parameterTypes ??= Type.EmptyTypes; m_signature = SignatureHelper.GetMethodSigHelper( m_module, m_callingConvention, m_inst != null ? m_inst.Length : 0, m_returnType, m_returnTypeRequiredCustomModifiers, m_returnTypeOptionalCustomModifiers, m_parameterTypes, m_parameterTypeRequiredCustomModifiers, m_parameterTypeOptionalCustomModifiers ); return(m_signature); }
internal SymbolMethod(ModuleBuilder mod, MethodToken token, Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) { this.m_mdMethod = token; this.m_returnType = returnType; if (parameterTypes != null) { this.m_parameterTypes = new Type[parameterTypes.Length]; Array.Copy((Array)parameterTypes, (Array)this.m_parameterTypes, parameterTypes.Length); } else { this.m_parameterTypes = EmptyArray <Type> .Value; } this.m_module = mod; this.m_containingType = arrayClass; this.m_name = methodName; this.m_callingConvention = callingConvention; this.m_signature = SignatureHelper.GetMethodSigHelper((Module)mod, callingConvention, returnType, (Type[])null, (Type[])null, parameterTypes, (Type[][])null, (Type[][])null); }
internal override SignatureHelper GetMemberRefSignature(CallingConventions call, Type returnType, Type[] parameterTypes, Type[] optionalParameterTypes) { int num = parameterTypes != null ? parameterTypes.Length : 0; SignatureHelper methodSigHelper = SignatureHelper.GetMethodSigHelper(call, returnType); for (int index = 0; index < num; ++index) { methodSigHelper.AddArgument(parameterTypes[index]); } if (optionalParameterTypes != null && optionalParameterTypes.Length != 0) { methodSigHelper.AddSentinel(); for (int index = 0; index < optionalParameterTypes.Length; ++index) { methodSigHelper.AddArgument(optionalParameterTypes[index]); } } return(methodSigHelper); }
private void Init( String name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Module mod, TypeBuilder type, bool bIsGlobalMethod) { m_strName = name; m_localSignature = SignatureHelper.GetLocalVarSigHelper(mod); 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(Environment.GetResourceString("Arg_NoStaticVirtual")); } 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)) { throw new ArgumentException(Environment.GetResourceString("Argument_BadAttributeOnInterfaceMethod")); } } } m_callingConvention = callingConvention; m_returnType = returnType; if (parameterTypes != null) { m_parameterTypes = new Type[parameterTypes.Length]; Array.Copy(parameterTypes, m_parameterTypes, parameterTypes.Length); } else { m_parameterTypes = null; } m_signature = SignatureHelper.GetMethodSigHelper(mod, callingConvention, returnType, parameterTypes); 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; }
// Constructor. internal MethodBuilder(TypeBuilder type, String name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) { // Validate the parameters. if (name == null) { throw new ArgumentNullException("name"); } else if (name == String.Empty) { throw new ArgumentException(_("Emit_NameEmpty")); } if (returnType == null) { returnType = typeof(void); } if ((attributes & MethodAttributes.Static) == 0) { callingConvention |= CallingConventions.HasThis; } else if ((attributes & MethodAttributes.Virtual) != 0) { throw new ArgumentException (_("Emit_BothStaticAndVirtual")); } if ((type.Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface && (attributes & MethodAttributes.SpecialName) == 0) { if ((attributes & (MethodAttributes.Virtual | MethodAttributes.Abstract)) != (MethodAttributes.Virtual | MethodAttributes.Abstract)) { throw new ArgumentException (_("Emit_InterfaceMethodAttrs")); } } // Set the local state. this.type = type; this.bodySet = false; this.initLocals = true; this.explicitBody = null; this.ilGenerator = null; this.returnType = returnType; this.returnBuilder = null; this.numParams = (parameterTypes != null ? parameterTypes.Length : 0); // Register this item to be detached later. type.module.assembly.AddDetach(this); // Create the method signature. helper = SignatureHelper.GetMethodSigHelper (type.module, callingConvention, (CallingConvention)0, returnType, parameterTypes); // Create the method. lock (typeof(AssemblyBuilder)) { this.privateData = ClrMethodCreate (((IClrProgramItem)type).ClrHandle, name, attributes, helper.sig); } // Add the method to the type for post-processing. type.AddMethod(this); }
public virtual void EmitCalli(OpCode opcode, CallingConvention unmanagedCallConv, Type returnType, Type[] parameterTypes) { SignatureHelper helper = SignatureHelper.GetMethodSigHelper(module, 0, unmanagedCallConv, returnType, parameterTypes); Emit(opcode, helper); }
/// <summary>Returns a signature helper for a method with a standard calling convention, given the method's module, return type, and argument types.</summary> /// <returns>The SignatureHelper object for a method.</returns> /// <param name="mod">The <see cref="T:System.Reflection.Emit.ModuleBuilder" /> that contains the method for which the SignatureHelper is requested. </param> /// <param name="returnType">The return type of the method, or null for a void return type (Sub procedure in Visual Basic). </param> /// <param name="parameterTypes">The types of the arguments of the method, or null if the method has no arguments. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="mod" /> is null.-or-An element of <paramref name="parameterTypes" /> is null.</exception> /// <exception cref="T:System.ArgumentException"> /// <paramref name="mod" /> is not a <see cref="T:System.Reflection.Emit.ModuleBuilder" />.</exception> public static SignatureHelper GetMethodSigHelper(Module mod, Type returnType, Type[] parameterTypes) { return(SignatureHelper.GetMethodSigHelper(mod, CallingConventions.Standard, (CallingConvention)0, returnType, parameterTypes)); }
/// <summary>Returns a signature helper for a method given the method's module, unmanaged calling convention, and return type.</summary> /// <returns>The SignatureHelper object for a method.</returns> /// <param name="mod">The <see cref="T:System.Reflection.Emit.ModuleBuilder" /> that contains the method for which the SignatureHelper is requested. </param> /// <param name="unmanagedCallConv">The unmanaged calling convention of the method. </param> /// <param name="returnType">The return type of the method, or null for a void return type (Sub procedure in Visual Basic). </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="mod" /> is null.</exception> /// <exception cref="T:System.ArgumentException"> /// <paramref name="mod" /> is not a <see cref="T:System.Reflection.Emit.ModuleBuilder" />.-or-<paramref name="unmanagedCallConv" /> is an unknown unmanaged calling convention.</exception> public static SignatureHelper GetMethodSigHelper(Module mod, CallingConvention unmanagedCallConv, Type returnType) { return(SignatureHelper.GetMethodSigHelper(mod, CallingConventions.Standard, unmanagedCallConv, returnType, null)); }
/// <summary>Returns a signature helper for a method given the method's module, calling convention, and return type.</summary> /// <returns>The SignatureHelper object for a method.</returns> /// <param name="mod">The <see cref="T:System.Reflection.Emit.ModuleBuilder" /> that contains the method for which the SignatureHelper is requested. </param> /// <param name="callingConvention">The calling convention of the method. </param> /// <param name="returnType">The return type of the method, or null for a void return type (Sub procedure in Visual Basic). </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="mod" /> is null.</exception> /// <exception cref="T:System.ArgumentException"> /// <paramref name="mod" /> is not a <see cref="T:System.Reflection.Emit.ModuleBuilder" />.</exception> public static SignatureHelper GetMethodSigHelper(Module mod, CallingConventions callingConvention, Type returnType) { return(SignatureHelper.GetMethodSigHelper(mod, callingConvention, (CallingConvention)0, returnType, null)); }