예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MethodSignature"/> class.
        /// </summary>
        /// <param name="context">The context of the generic method spec signature.</param>
        /// <param name="signature">The signature of the generic method.</param>
        /// <param name="specification">The signature specifying replacements for the generic signature.</param>
        public MethodSignature(ISignatureContext context, MethodSignature signature, MethodSpecSignature specification)
        {
            if (context == null)
                throw new ArgumentNullException(@"context");
            if (signature == null)
                throw new ArgumentNullException(@"signature");
            if (specification == null)
                throw new ArgumentNullException(@"specification");

            this._callingConvention = signature.CallingConvention;
            this._hasExplicitThis = signature.HasExplicitThis;
            this._hasThis = signature.HasThis;
            this._genericParameterCount = 0;

            int length = signature.Parameters.Length;
            this._parameters = new SigType[length];
            for (int index = 0; index < length; index++)
            {
                this._parameters[index] = this.ApplySpecification(context, specification, signature.Parameters[index]);
            }
            this._returnType = this.ApplySpecification(context, specification, signature.ReturnType);
        }
예제 #2
0
        private SigType ApplySpecification(ISignatureContext context, MethodSpecSignature specification, SigType sigType)
        {
            SigType result = sigType;

            if (sigType is VarSigType)
            {
                result = context.GetGenericTypeArgument(((VarSigType)sigType).Index);
            }
            else if (sigType is MVarSigType)
            {
                result = specification.Types[((MVarSigType)sigType).Index];
            }

            Debug.WriteLine(String.Format(@"Replaced {0} by {1}.", sigType, result));
            return result;
        }
        /// <summary>
        /// Decodes the method specification
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        private RuntimeMethod DecodeMethodSpec(TokenTypes token)
        {
            MethodSpecRow methodSpec = metadata.ReadMethodSpecRow(token);

            CilRuntimeMethod genericMethod = (CilRuntimeMethod)((IModuleTypeSystem)this).GetMethod(methodSpec.MethodTableIdx);

            MethodSpecSignature specSignature = new MethodSpecSignature(metadata, methodSpec.InstantiationBlobIdx);

            MethodSignature signature = new MethodSignature(genericMethod.MetadataModule.Metadata, genericMethod.Signature.Token);

            return new CilGenericMethod(this, genericMethod, signature, genericMethod.DeclaringType);
        }