public FunctionSignature(UInt32 uiMethodAttributes, string strReturnType, string strClassName, string strFunctionName, string strParameters) { CorMethodAttr cma = ( CorMethodAttr )uiMethodAttributes; _bIsPInvoke = (cma & CorMethodAttr.mdPinvokeImpl) != 0; _bIsStatic = (cma & CorMethodAttr.mdStatic) != 0; _bIsExtern = (cma & CorMethodAttr.mdUnmanagedExport) != 0; _strReturnType = strReturnType; _strClassName = strClassName; _strFunctionName = strFunctionName; _strParameters = strParameters; }
public Method(uint token, Type declaringType) : base(token) { char[] szName = new char[1024]; uint outNameSize; uint tokclass, attr, sigBlobSize, codeRVA, implFlags; IntPtr sigBlob; Context.importIntf.GetMethodProps (this.token, out tokclass, szName, 1024, out outNameSize, out attr, out sigBlob, out sigBlobSize, out codeRVA, out implFlags); if ((int)outNameSize <= 1) { throw new ArgumentException ("Method without names unsupported: token is 0x" + token.ToString("x")); } else { this.name = Decoder.ReadString(szName, (int)outNameSize); } int idx = 0; this.flags = (CorMethodAttr)attr; this.declaringType = declaringType; // start reading the signature of this method int nParams, nGenericParams; CorCallingConvention b = (CorCallingConvention)Decoder.ReadValue(sigBlob, ref idx); // first byte contains the flags for HASTHIS, EXPLICITTHIS AND Default/Vararg/Generic calling conventions. if ((b & CorCallingConvention.UPMASK) == CorCallingConvention.HASTHIS) { this.hasThis = true; if ((b & CorCallingConvention.UPMASK) == CorCallingConvention.EXPLICITTHIS) { this.explicitThis = true; } } nGenericParams = 0; if ((b & CorCallingConvention.VARARG) != 0) { throw new System.ArgumentException(this.name + ": Vararg methods not supported"); } else if ((b & CorCallingConvention.GENERIC) != 0) { this.callconv = CallingConvention.Generic; nGenericParams = (int)Decoder.ReadCompressed(sigBlob, ref idx); } // Retrieve first the generic parameters, as the regular ones might reverence those if (nGenericParams > 0) { IntPtr hHandle = IntPtr.Zero; int countTokens = 0; uint[] tokenRef = new uint[1]; Context.importIntf.EnumGenericParams(ref hHandle, this.token, tokenRef, 1, out countTokens); this.genParameters = new List <GenericParam>(); while (countTokens > 0) { try { this.genParameters.Add(new GenericParam(tokenRef[0])); } catch (System.ArgumentException e) { // better message formating throw new System.ArgumentException(string.Format("Unsupported generic argument in method {0} : {1}", e.Message, this.name)); } Context.importIntf.EnumGenericParams(ref hHandle, this.token, tokenRef, 1, out countTokens); } Context.importIntf.CloseEnum(hHandle); } // Now read the parameters nParams = Decoder.ReadCompressed(sigBlob, ref idx); this.retType = new Param(sigBlob, ref idx, this); { this.parameters = new List <Param>(); IntPtr hHandle = IntPtr.Zero; int countTokens = 0; uint[] tokenRef = new uint[1]; Context.importIntf.EnumParams(ref hHandle, this.token, tokenRef, 1, out countTokens); while (countTokens > 0) { // create the corresponding object Param p = null; // some parameters returned by the enumerator are useless informative token // this raises an exception that we ignore here. try { p = new Param(tokenRef[0], this); } catch { p = null; } if (p != null) { try { p.SetSig(sigBlob, ref idx, this); this.parameters.Add(p); } catch (System.ArgumentException e) { throw new System.ArgumentException ("Unsupported parameter " + p.Name + " in method " + this.Name + ": " + e.Message); } } Context.importIntf.EnumParams(ref hHandle, this.token, tokenRef, 1, out countTokens); } Context.importIntf.CloseEnum(hHandle); } }