Ejemplo n.º 1
0
        DmdCustomAttributeData Read(DmdConstructorInfo ctor)
        {
            var  ctorParams = ctor.GetMethodSignature().GetParameterTypes();
            bool isEmpty    = ctorParams.Count == 0 && reader.Position == reader.Length;

            if (!isEmpty && reader.ReadUInt16() != 1)
            {
                throw new CABlobParserException("Invalid CA blob prolog");
            }

            var ctorArgs = new DmdCustomAttributeTypedArgument[ctorParams.Count];

            for (int i = 0; i < ctorArgs.Length; i++)
            {
                ctorArgs[i] = ReadFixedArg(FixTypeSig(ctorParams[i]));
            }

            // Some tools don't write the next ushort if there are no named arguments.
            int numNamedArgs = reader.Position == reader.Length ? 0 : reader.ReadUInt16();
            var namedArgs    = ReadNamedArguments(numNamedArgs);

            // Match reflection named argument order: fields before properties,
            // and order of fields/properties is identical to the order returned
            // by GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) and
            // GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).
            Array.Sort(namedArgs, ReflectionNamedArgumentComparerDelegate);

            return(new DmdCustomAttributeData(ctor, ctorArgs, namedArgs, isPseudoCustomAttribute: false));
        }
Ejemplo n.º 2
0
        bool ReadHeader(out int localSignatureMetadataToken, out int maxStackSize, out bool initLocals, out int codeSize, out bool hasExceptionHandlers)
        {
            byte b = reader.ReadByte();

            switch (b & 7)
            {
            case 2:
            case 6:
                localSignatureMetadataToken = 0;
                maxStackSize         = 8;
                initLocals           = false;
                codeSize             = b >> 2;
                hasExceptionHandlers = false;
                return(true);

            case 3:
                uint flags      = (ushort)((reader.ReadByte() << 8) | b);
                int  headerSize = (int)(flags >> 12);
                initLocals   = (flags & 0x10) != 0;
                maxStackSize = reader.ReadUInt16();
                codeSize     = reader.ReadInt32();
                localSignatureMetadataToken = reader.ReadInt32();
                hasExceptionHandlers        = (flags & 8) != 0;

                reader.Position += -12 + headerSize * 4;
                if (headerSize < 3)
                {
                    hasExceptionHandlers = false;
                }
                return(true);

            default:
                localSignatureMetadataToken = 0;
                maxStackSize         = 0;
                initLocals           = false;
                codeSize             = 0;
                hasExceptionHandlers = false;
                return(false);
            }
        }