示例#1
0
        public CLRSigPropertySig(CLRSignatureParser parser)
        {
            CLRSignatureParser.Token headToken = parser.NextToken();
            parser.ConsumeToken();

            if (headToken == CLRSignatureParser.Token.PROPERTY_HASTHIS)
                HasThis = true;
            else if (headToken == CLRSignatureParser.Token.PROPERTY)
                HasThis = false;
            else
                throw new ParseFailedException("Malformed PropertySig");

            uint paramCount = parser.ReadCompressedUInt();
            CustomMods = CLRSigType.ReadCustomMods(parser);

            Type = CLRSigType.Parse(parser, false);

            Parameters = new CLRSigParamType[paramCount];
            for (uint i = 0; i < paramCount; i++)
                Parameters[i] = new CLRSigParamType(parser, false);
        }
        public CLRSigMethodDefOrRefSig(CLRSignatureParser parser, Kind allowedKind)
        {
            byte baseByte = parser.NextByte();
            parser.ConsumeByte();

            CLRSignatureParser.Token callingConvention = (CLRSignatureParser.Token)(baseByte & 0x0f);

            if ((baseByte & (byte)CLRSignatureParser.Token.HASTHIS) != 0)
            {
                HasThis = true;
                if ((baseByte & (byte)CLRSignatureParser.Token.EXPLICITTHIS) != 0)
                    ExplicitThis = true;
            }

            if ((baseByte & (int)CLRSignatureParser.Token.GENERIC) != 0)
            {
                if (allowedKind != Kind.Def && allowedKind != Kind.DefOrRef && allowedKind != Kind.Ref)
                    throw new ParseFailedException("Invalid method signature");
                allowedKind = Kind.Def;
                NumGenericParameters = parser.ReadCompressedUInt();
            }

            switch (callingConvention)
            {
                case CLRSignatureParser.Token.DEFAULT:
                    if (allowedKind != Kind.Def && allowedKind != Kind.DefOrRef && allowedKind != Kind.Ref)
                        throw new ParseFailedException("Invalid method signature");
                    allowedKind = Kind.Def;
                    CallingConvention = CallingConventionType.Default;
                    break;
                case CLRSignatureParser.Token.VARARG:
                    CallingConvention = CallingConventionType.VarArg;
                    break;
                case CLRSignatureParser.Token.C:
                    if (allowedKind != Kind.StandAlone)
                        throw new ParseFailedException("Invalid method signature");
                    CallingConvention = CallingConventionType.C;
                    break;
                case CLRSignatureParser.Token.STDCALL:
                    if (allowedKind != Kind.StandAlone)
                        throw new ParseFailedException("Invalid method signature");
                    CallingConvention = CallingConventionType.StdCall;
                    break;
                case CLRSignatureParser.Token.THISCALL:
                    if (allowedKind != Kind.StandAlone)
                        throw new ParseFailedException("Invalid method signature");
                    CallingConvention = CallingConventionType.ThisCall;
                    break;
                case CLRSignatureParser.Token.FASTCALL:
                    if (allowedKind != Kind.StandAlone)
                        throw new ParseFailedException("Invalid method signature");
                    CallingConvention = CallingConventionType.FastCall;
                    break;
                default:
                    throw new ParseFailedException("Unexpected signature token");
            }
            uint paramCount = parser.ReadCompressedUInt();

            // Return type
            RetType = new CLRSigRetType(parser);

            ParamTypes = new CLRSigParamType[paramCount];

            bool allowSentinel = (allowedKind == Kind.StandAlone) && (CallingConvention == CallingConventionType.C || CallingConvention == CallingConventionType.VarArg);

            // Parameter types
            for (uint i = 0; i < paramCount; i++)
                ParamTypes[i] = new CLRSigParamType(parser, allowSentinel);
        }