public CustomAttributeSignature(CustomAttributeArgument[] fixedArgs, CustomAttributeArgument[] namedArgs)
 {
     FixedArguments = fixedArgs;
     NamedArguments = namedArgs;
 }
Ejemplo n.º 2
0
        public CustomAttributeSignature ReadCustomAttributeSignature(CustomAttribute parent, uint signature)
        {
            CustomAttributeSignature customAttrSig = null;
            using (BinaryReader reader = GetBlobReader(signature))
            {
                ushort sign = reader.ReadUInt16();
                if (sign != 0x0001)
                    throw new ArgumentException("Signature doesn't refer to a valid Custom Attribute signature");

                int fixedArgCount = 0;

                if (parent.Constructor.Signature != null && parent.Constructor.Signature.Parameters != null)
                    fixedArgCount = parent.Constructor.Signature.Parameters.Length;

                CustomAttributeArgument[] fixedArgs = new CustomAttributeArgument[fixedArgCount];

                for (int i = 0; i < fixedArgCount; i++)
                {
                    fixedArgs[i] = new CustomAttributeArgument(ReadArgumentValue(reader,parent.Constructor.Signature.Parameters[i].ParameterType));

                }

                int namedArgCount = 0;
                CustomAttributeArgument[] namedArgs = new CustomAttributeArgument[namedArgCount];

                customAttrSig = new CustomAttributeSignature(fixedArgs, namedArgs);
            }
            return customAttrSig;
        }
Ejemplo n.º 3
0
        public CustomAttributeSignature ReadCustomAttributeSignature(CustomAttribute parent, uint signature)
        {
            CustomAttributeSignature customAttrSig = null;
            BlobSignatureReader reader;
            if (TryGetBlobReader(signature, out reader))
            {
                using (reader)
                {
                    ushort sign = reader.ReadUInt16();
                    if (sign != 0x0001)
                        throw new ArgumentException("Signature doesn't refer to a valid Custom Attribute signature");

                    int fixedArgCount = 0;

                    if (parent.Constructor.Signature != null && parent.Constructor.Signature.Parameters != null)
                        fixedArgCount = parent.Constructor.Signature.Parameters.Length;

                    CustomAttributeArgument[] fixedArgs = new CustomAttributeArgument[fixedArgCount];
                    bool canReadNamedArgs = true; // temporary solution for skipping named args when fixed args failed.
                    for (int i = 0; i < fixedArgCount; i++)
                    {
                        fixedArgs[i] = new CustomAttributeArgument(reader.ReadCustomAttributeArgumentValue(parent.Constructor.Signature.Parameters[i].ParameterType));
                        if (fixedArgs[i].Value == null)
                            canReadNamedArgs = false;
                    }

                    CustomAttributeArgument[] namedArgs = null;
                    if (!reader.EndOfStream && canReadNamedArgs)
                    {
                        int namedArgCount = reader.ReadUInt16();
                        namedArgs = new CustomAttributeArgument[namedArgCount];

                        for (int i = 0; i < namedArgCount; i++)
                        {
                            byte argSignature = reader.ReadByte();
                            TypeReference argType = reader.ReadCustomAttributeFieldOrPropType();
                            string name = reader.ReadUtf8String();
                            namedArgs[i] = new CustomAttributeArgument(reader.ReadCustomAttributeArgumentValue(argType), name, argSignature == 0x53 ? CustomAttributeArgumentType.NamedField : CustomAttributeArgumentType.NamedProperty);
                        }
                    }

                    customAttrSig = new CustomAttributeSignature(fixedArgs, namedArgs);
                }
            }
            return customAttrSig;
        }