FromReader() 공개 정적인 메소드

public static FromReader ( MetadataHeader header, IBinaryStreamReader reader ) : CustomAttributeNamedArgument
header MetadataHeader
reader IBinaryStreamReader
리턴 CustomAttributeNamedArgument
예제 #1
0
        public static CustomAttributeSignature FromReader(CustomAttribute parent, IBinaryStreamReader reader)
        {
            if (!reader.CanRead(sizeof(ushort)) || reader.ReadUInt16() != 0x0001)
            {
                throw new ArgumentException("Signature doesn't refer to a valid custom attribute signature.");
            }

            var signature = new CustomAttributeSignature();

            if (parent.Constructor != null)
            {
                var methodSignature = parent.Constructor.Signature as MethodSignature;
                if (methodSignature != null)
                {
                    foreach (var parameter in methodSignature.Parameters)
                    {
                        signature.FixedArguments.Add(CustomAttributeArgument.FromReader(parent.Image, parameter.ParameterType, reader));
                    }
                }
            }

            var namedElementCount = reader.CanRead(sizeof(ushort)) ? reader.ReadUInt16() : 0;

            for (uint i = 0; i < namedElementCount; i++)
            {
                signature.NamedArguments.Add(CustomAttributeNamedArgument.FromReader(parent.Image, reader));
            }

            return(signature);
        }
        /// <summary>
        /// Reads a single security attribute at the current position of the provided stream reader.
        /// </summary>
        /// <param name="image">The image the signature resides in.</param>
        /// <param name="reader">The reader to use.</param>
        /// <returns>The read attribute.</returns>
        public static SecurityAttributeSignature FromReader(MetadataImage image, IBinaryStreamReader reader)
        {
            var signature = new SecurityAttributeSignature
            {
                TypeName = reader.ReadSerString(),
            };

            reader.ReadCompressedUInt32();

            if (!reader.TryReadCompressedUInt32(out uint argumentCount))
            {
                return(signature);
            }

            if (argumentCount == 0)
            {
                return(signature);
            }

            for (int i = 0; i < argumentCount; i++)
            {
                signature.NamedArguments.Add(CustomAttributeNamedArgument.FromReader(image, reader));
            }

            return(signature);
        }