Ejemplo n.º 1
0
 /// <summary>
 /// Reads a single field signature from an input stream.
 /// </summary>
 /// <param name="module">The module containing the signature.</param>
 /// <param name="reader">The blob input stream.</param>
 /// <param name="protection">The object responsible for detecting infinite recursion.</param>
 /// <returns>The field signature.</returns>
 public static FieldSignature FromReader(ModuleDefinition module, IBinaryStreamReader reader,
                                         RecursionProtection protection)
 {
     return(new FieldSignature(
                (CallingConventionAttributes)reader.ReadByte(),
                TypeSignature.FromReader(module, reader, protection)));
 }
Ejemplo n.º 2
0
 public TypeSpecification(MetadataImage image, MetadataRow <uint> row)
     : base(row.MetadataToken)
 {
     _signature = new LazyValue <TypeSignature>(() =>
                                                TypeSignature.FromReader(image, image.Header.GetStream <BlobStream>().CreateBlobReader(row.Column1)));
     CustomAttributes = new CustomAttributeCollection(this);
 }
        public void ReadCorLibType(ElementType elementType)
        {
            var blob    = new[] { (byte)elementType };
            var module  = new ModuleDefinition("SomeModule");
            var typeSig = TypeSignature.FromReader(module, new ByteArrayReader(blob));

            Assert.Equal(elementType, typeSig.ElementType);
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        protected override TypeSignature GetSignature()
        {
            var reader = _parentModule.DotNetDirectory.Metadata
                         .GetStream <BlobStream>()
                         .GetBlobReaderByIndex(_row.Signature);

            var protection = RecursionProtection.CreateNew();

            protection.TraversedTokens.Add(MetadataToken);
            return(TypeSignature.FromReader(_parentModule, reader, protection));
        }
Ejemplo n.º 5
0
 internal TypeSpecification(MetadataImage image, MetadataRow <uint> row)
     : base(row.MetadataToken)
 {
     _image     = image;
     _signature = new TaggedLazyValue <RecursionProtection, TypeSignature>(protection =>
     {
         protection.TraversedTokens.Add(row.MetadataToken);
         return(TypeSignature.FromReader(
                    image,
                    image.Header.GetStream <BlobStream>().CreateBlobReader(row.Column1),
                    true,
                    protection));
     },
                                                                           RecursionProtection.Create);
     CustomAttributes = new CustomAttributeCollection(this);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Reads a single local variables signature from the provided input stream.
        /// </summary>
        /// <param name="parentModule">The module containing the signature.</param>
        /// <param name="reader">The input stream.</param>
        /// <param name="protection">The object responsible for detecting infinite recursion.</param>
        /// <returns>The signature.</returns>
        public static LocalVariablesSignature FromReader(ModuleDefinition parentModule, IBinaryStreamReader reader, RecursionProtection protection)
        {
            var result = new LocalVariablesSignature();

            result.Attributes = (CallingConventionAttributes)reader.ReadByte();

            if (!reader.TryReadCompressedUInt32(out uint count))
            {
                return(result);
            }

            for (int i = 0; i < count; i++)
            {
                result.VariableTypes.Add(TypeSignature.FromReader(parentModule, reader, protection));
            }

            return(result);
        }
        internal static GenericInstanceMethodSignature FromReader(ModuleDefinition parentModule,
                                                                  IBinaryStreamReader reader, RecursionProtection protection)
        {
            if (!reader.CanRead(sizeof(byte)))
            {
                return(null);
            }

            var attributes = (CallingConventionAttributes)reader.ReadByte();
            var result     = new GenericInstanceMethodSignature(attributes);

            if (!reader.TryReadCompressedUInt32(out uint count))
            {
                return(result);
            }

            for (int i = 0; i < count; i++)
            {
                result.TypeArguments.Add(TypeSignature.FromReader(parentModule, reader, protection));
            }

            return(result);
        }
Ejemplo n.º 8
0
 internal TypeSpecification(MetadataHeader header, MetadataToken token, MetadataRow <uint> row)
     : base(header, token, row)
 {
     _signature = new LazyValue <TypeSignature>(() =>
                                                TypeSignature.FromReader(header, header.GetStream <BlobStream>().CreateBlobReader(row.Column1)));
 }