示例#1
0
		internal static DmdCustomAttributeNamedArgument[] ReadNamedArguments(DmdModule module, DmdDataStream stream, DmdType ctorReflectedType, int numNamedArgs, IList<DmdType> genericTypeArguments) {
			using (var reader = new DmdCustomAttributeReader(module, stream, ctorReflectedType, genericTypeArguments, ownsReader: false)) {
				try {
					return reader.ReadNamedArguments(numNamedArgs);
				}
				catch (CABlobParserException) {
				}
				catch (ResolveException) {
				}
				catch (IOException) {
				}
				return null;
			}
		}
示例#2
0
		public static DmdCustomAttributeData Read(DmdModule module, DmdDataStream stream, DmdConstructorInfo ctor) {
			using (var reader = new DmdCustomAttributeReader(module, stream, ctor.ReflectedType, GetGenericArguments(ctor.ReflectedType), ownsReader: true)) {
				try {
					return reader.Read(ctor);
				}
				catch (CABlobParserException) {
				}
				catch (ResolveException) {
				}
				catch (IOException) {
				}
				return null;
			}
		}
        // Reads the new (.NET 2.0+) DeclSecurity blob format
        DmdCustomAttributeData[] ReadBinaryFormat(SecurityAction action)
        {
            int numAttrs = (int)reader.ReadCompressedUInt32();

            DmdCustomAttributeData[]? res = new DmdCustomAttributeData[numAttrs];

            IList <DmdType>?genericTypeArguments = null;
            int             w = 0;

            for (int i = 0; i < numAttrs; i++)
            {
                var name = ReadUTF8String();
                var type = DmdTypeNameParser.ParseThrow(module, name ?? string.Empty, genericTypeArguments);
                reader.ReadCompressedUInt32();                // int blobLength
                int numNamedArgs = (int)reader.ReadCompressedUInt32();
                var namedArgs    = DmdCustomAttributeReader.ReadNamedArguments(module, reader, type, numNamedArgs, genericTypeArguments);
                if (namedArgs is null)
                {
                    throw new IOException();
                }
                var(ctor, ctorArguments) = GetConstructor(type, action);
                Debug.Assert(!(ctor is null));
                if (ctor is null)
                {
                    continue;
                }
                res[w++] = new DmdCustomAttributeData(ctor, ctorArguments, namedArgs, isPseudoCustomAttribute: false);
            }
            if (res.Length != w)
            {
                if (w == 0)
                {
                    return(Array.Empty <DmdCustomAttributeData>());
                }
                Array.Resize(ref res, w);
            }

            return(res !);
        }