示例#1
0
        internal static (IType, IParameter[]) DecodeSignature(MetadataModule module, IParameterizedMember owner, MethodSignature <IType> signature, ParameterHandleCollection?parameterHandles)
        {
            var metadata = module.metadata;
            int i        = 0;
            CustomAttributeHandleCollection?returnTypeAttributes = null;

            IParameter[] parameters = new IParameter[signature.RequiredParameterCount
                                                     + (signature.Header.CallingConvention == SignatureCallingConvention.VarArgs ? 1 : 0)];
            IType parameterType;

            if (parameterHandles != null)
            {
                foreach (var parameterHandle in parameterHandles)
                {
                    var par = metadata.GetParameter(parameterHandle);
                    if (par.SequenceNumber == 0)
                    {
                        // "parameter" holds return type attributes
                        returnTypeAttributes = par.GetCustomAttributes();
                    }
                    else if (par.SequenceNumber > 0 && i < signature.RequiredParameterCount)
                    {
                        // "Successive rows of the Param table that are owned by the same method shall be
                        // ordered by increasing Sequence value - although gaps in the sequence are allowed"
                        Debug.Assert(i < par.SequenceNumber);
                        // Fill gaps in the sequence with non-metadata parameters:
                        while (i < par.SequenceNumber - 1)
                        {
                            parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType(
                                signature.ParameterTypes[i], module.Compilation, null, metadata, module.TypeSystemOptions);
                            parameters[i] = new DefaultParameter(parameterType, name: string.Empty, owner,
                                                                 isRef: parameterType.Kind == TypeKind.ByReference);
                            i++;
                        }
                        parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType(
                            signature.ParameterTypes[i], module.Compilation,
                            par.GetCustomAttributes(), metadata, module.TypeSystemOptions);
                        parameters[i] = new MetadataParameter(module, owner, parameterType, parameterHandle);
                        i++;
                    }
                }
            }
            while (i < signature.RequiredParameterCount)
            {
                parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType(
                    signature.ParameterTypes[i], module.Compilation, null, metadata, module.TypeSystemOptions);
                parameters[i] = new DefaultParameter(parameterType, name: string.Empty, owner,
                                                     isRef: parameterType.Kind == TypeKind.ByReference);
                i++;
            }
            if (signature.Header.CallingConvention == SignatureCallingConvention.VarArgs)
            {
                parameters[i] = new DefaultParameter(SpecialType.ArgList, name: string.Empty, owner);
                i++;
            }
            Debug.Assert(i == parameters.Length);
            var returnType = ApplyAttributeTypeVisitor.ApplyAttributesToType(signature.ReturnType,
                                                                             module.Compilation, returnTypeAttributes, metadata, module.TypeSystemOptions);

            return(returnType, parameters);
        }
示例#2
0
 public override string ToString()
 {
     return(DefaultParameter.ToString(this));
 }
 public override string ToString()
 {
     return($"{MetadataTokens.GetToken(handle):X8} {DefaultParameter.ToString(this)}");
 }