/// <summary> /// Loads all methods From the given metadata module. /// </summary> /// <param name="module">The metadata module to load methods From.</param> /// <param name="declaringType">The type, which declared the method.</param> /// <param name="first">The first method token to load.</param> /// <param name="last">The last method token to load (non-inclusive.)</param> /// <param name="offset">The offset into the method table to start loading methods From.</param> private void LoadMethods(IMetadataModule module, RuntimeType declaringType, TokenTypes first, TokenTypes last, ref int offset) { IMetadataProvider md = module.Metadata; MethodDefRow methodDef, nextMethodDef = new MethodDefRow(); TokenTypes maxParam, maxMethod = md.GetMaxTokenValue(TokenTypes.MethodDef); if (first < last) { md.Read(first, out methodDef); for (TokenTypes token = first; token < last; token++) { if (token < maxMethod) { md.Read(token + 1, out nextMethodDef); maxParam = nextMethodDef.ParamList; } else { maxParam = md.GetMaxTokenValue(TokenTypes.Param) + 1; } Debug.Assert(offset < _methods.Length, @"Invalid method index."); _methods[offset++] = new CilRuntimeMethod(offset, module, ref methodDef, maxParam, declaringType); methodDef = nextMethodDef; } } }
/// <summary> /// Initializes a new instance of the <see cref="CilGenericMethod"/> class. /// </summary> /// <param name="module">The module.</param> /// <param name="genericMethod">The generic method.</param> /// <param name="signature">The signature.</param> /// <param name="declaringType">Type of the declaring.</param> public CilGenericMethod(ITypeModule module, CilRuntimeMethod genericMethod, MethodSignature signature, RuntimeType declaringType) : base(module, genericMethod.Token, declaringType) { this.Signature = signature; this.Attributes = genericMethod.Attributes; this.ImplAttributes = genericMethod.ImplAttributes; this.Rva = genericMethod.Rva; this.Parameters = genericMethod.Parameters; base.Name = genericMethod.Name; }
/// <summary> /// Loads all methods from the given metadata module. /// </summary> /// <param name="declaringType">The type, which declared the method.</param> /// <param name="first">The first method token to load.</param> /// <param name="last">The last method token to load (non-inclusive.)</param> private void LoadMethods(RuntimeType declaringType, Token first, Token last) { if (first.RID >= last.RID) { return; } Token maxMethod = GetMaxTokenValue(TableType.MethodDef); MethodDefRow methodDef = metadataProvider.ReadMethodDefRow(first); MethodDefRow nextMethodDef = new MethodDefRow(); foreach (Token token in first.Upto(last.PreviousRow)) { Token maxParam; if (token.RID < maxMethod.RID) { nextMethodDef = metadataProvider.ReadMethodDefRow(token.NextRow); maxParam = nextMethodDef.ParamList; } else { maxParam = GetMaxTokenValue(TableType.Param).NextRow; } CilRuntimeMethod method = new CilRuntimeMethod( this, GetString(methodDef.NameStringIdx), GetMethodSignature(methodDef.SignatureBlobIdx), token, declaringType, methodDef.Flags, methodDef.ImplFlags, methodDef.Rva ); LoadParameters(method, methodDef.ParamList, maxParam); declaringType.Methods.Add(method); methods[token.RID - 1] = method; methodDef = nextMethodDef; } }