Exemplo 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));
        }
Exemplo n.º 2
0
		DmdCustomAttributeTypedArgument ReadArrayArgument(DmdType arrayType) {
			if (!arrayType.IsSZArray)
				throw new ArgumentException();
			if (!IncrementRecursionCounter())
				throw new CABlobParserException("Stack overflow");

			object argValue;
			int arrayCount = reader.ReadInt32();
			if (arrayCount == -1)// -1 if it's null
				argValue = null;
			else if (arrayCount < 0)
				throw new CABlobParserException("Array is too big");
			else {
				var array = new DmdCustomAttributeTypedArgument[arrayCount];
				var elemType = FixTypeSig(arrayType.GetElementType());
				for (int i = 0; i < array.Length; i++)
					array[i] = ReadFixedArg(elemType);
				argValue = ReadOnlyCollectionHelpers.Create(array);
			}

			DecrementRecursionCounter();
			return new DmdCustomAttributeTypedArgument(arrayType, argValue);
		}