Пример #1
0
        public override void Write(MetadataBuffer buffer, IBinaryStreamWriter writer)
        {
            if (!Validate())
            {
                throw new InvalidOperationException();
            }

            writer.WriteByte((byte)ElementType);
            BaseType.Write(buffer, writer);
            writer.WriteCompressedUInt32((uint)Dimensions.Count);

            var sizedDimensions = Dimensions.Where(x => x.Size.HasValue).ToArray();

            writer.WriteCompressedUInt32((uint)sizedDimensions.Length);
            foreach (var sizedDimension in sizedDimensions)
            {
                writer.WriteCompressedUInt32((uint)sizedDimension.Size.Value);
            }

            var boundedDimensions = Dimensions.Where(x => x.LowerBound.HasValue).ToArray();

            writer.WriteCompressedUInt32((uint)boundedDimensions.Length);
            foreach (var boundedDimension in boundedDimensions)
            {
                writer.WriteCompressedUInt32((uint)boundedDimension.LowerBound.Value);
            }

            base.Write(buffer, writer);
        }
        /// <inheritdoc />
        protected override void WriteContents(IBinaryStreamWriter writer, ITypeCodedIndexProvider provider)
        {
            if (!Validate())
            {
                throw new InvalidOperationException();
            }

            writer.WriteByte((byte)ElementType);
            BaseType.Write(writer, provider);
            writer.WriteCompressedUInt32((uint)Dimensions.Count);

            // Sized dimensions.
            var sizedDimensions = Dimensions
                                  .Where(x => x.Size.HasValue)
                                  .ToArray();

            writer.WriteCompressedUInt32((uint)sizedDimensions.Length);
            foreach (var sizedDimension in sizedDimensions)
            {
                writer.WriteCompressedUInt32((uint)sizedDimension.Size.Value);
            }

            // Bounded dimensions.
            var boundedDimensions = Dimensions
                                    .Where(x => x.LowerBound.HasValue)
                                    .ToArray();

            writer.WriteCompressedUInt32((uint)boundedDimensions.Length);
            foreach (var boundedDimension in boundedDimensions)
            {
                writer.WriteCompressedUInt32((uint)boundedDimension.LowerBound.Value);
            }
        }
 /// <inheritdoc />
 protected override void WriteContents(IBinaryStreamWriter writer, ITypeCodedIndexProvider provider)
 {
     writer.WriteByte((byte)NativeType);
     if (Size.HasValue)
     {
         writer.WriteCompressedUInt32((uint)Size.Value);
         if (ArrayElementType.HasValue)
         {
             writer.WriteCompressedUInt32((uint)ArrayElementType);
         }
     }
 }
Пример #4
0
 public override void Write(MetadataBuffer buffer, IBinaryStreamWriter writer)
 {
     writer.WriteByte((byte)NativeType);
     writer.WriteByte((byte)ElementType);
     if (ParameterIndex.HasValue)
     {
         writer.WriteCompressedUInt32((uint)ParameterIndex.Value);
         if (NumberOfElements.HasValue)
         {
             writer.WriteCompressedUInt32((uint)NumberOfElements.Value);
         }
     }
 }
Пример #5
0
        public override void Write(MetadataBuffer buffer, IBinaryStreamWriter writer)
        {
            writer.WriteByte((byte)Attributes);

            if (IsGeneric)
            {
                writer.WriteCompressedUInt32((uint)GenericParameterCount);
            }

            writer.WriteCompressedUInt32((uint)Parameters.Count);
            ReturnType.Write(buffer, writer);
            foreach (var parameter in Parameters)
            {
                parameter.Write(buffer, writer);
            }
        }
        /// <inheritdoc />
        public override void Write(MetadataBuffer buffer, IBinaryStreamWriter writer)
        {
            writer.WriteByte((byte)ElementType);
            writer.WriteCompressedUInt32((uint)Index);

            base.Write(buffer, writer);
        }
Пример #7
0
        protected static void WriteTypeDefOrRef(MetadataHeader header, IBinaryStreamWriter writer, ITypeDefOrRef type)
        {
            var encoder =
                header.GetStream <TableStream>()
                .GetIndexEncoder(CodedIndex.TypeDefOrRef);

            writer.WriteCompressedUInt32(encoder.EncodeToken(type.MetadataToken));
        }
Пример #8
0
 public override void Write(MetadataBuffer buffer, IBinaryStreamWriter writer)
 {
     writer.WriteByte((byte)'.');
     writer.WriteCompressedUInt32((uint)Attributes.Count);
     foreach (var attribute in Attributes)
     {
         attribute.Write(buffer, writer);
     }
 }
        /// <inheritdoc />
        protected override void WriteContents(IBinaryStreamWriter writer, ITypeCodedIndexProvider provider)
        {
            writer.WriteByte((byte)NativeType);

            if (IidParameterIndex.HasValue)
            {
                writer.WriteCompressedUInt32((uint)IidParameterIndex.Value);
            }
        }
 public override void Write(MetadataBuffer buffer, IBinaryStreamWriter writer)
 {
     writer.WriteByte(0x0A);
     writer.WriteCompressedUInt32((uint)GenericArguments.Count);
     foreach (var argument in GenericArguments)
     {
         argument.Write(buffer, writer);
     }
 }
Пример #11
0
 public override void Write(MetadataBuffer buffer, IBinaryStreamWriter writer)
 {
     writer.WriteByte(0x07);
     writer.WriteCompressedUInt32((uint)Variables.Count);
     foreach (var variable in Variables)
     {
         variable.Write(buffer, writer);
     }
 }
 /// <inheritdoc />
 protected override void WriteContents(IBinaryStreamWriter writer, ITypeCodedIndexProvider provider)
 {
     writer.WriteByte((byte)Attributes);
     writer.WriteCompressedUInt32((uint)TypeArguments.Count);
     for (int i = 0; i < TypeArguments.Count; i++)
     {
         TypeArguments[i].Write(writer, provider);
     }
 }
Пример #13
0
        /// <inheritdoc />
        protected override void WriteContents(IBinaryStreamWriter writer, ITypeCodedIndexProvider provider)
        {
            writer.WriteByte((byte)Attributes);
            writer.WriteCompressedUInt32((uint)VariableTypes.Count);

            foreach (var type in VariableTypes)
            {
                type.Write(writer, provider);
            }
        }
Пример #14
0
 public override void Write(MetadataBuffer buffer, IBinaryStreamWriter writer)
 {
     writer.WriteByte((byte)Attributes);
     writer.WriteCompressedUInt32((uint)Parameters.Count);
     PropertyType.Write(buffer, writer);
     foreach (var parameter in Parameters)
     {
         parameter.Write(buffer, writer);
     }
 }
        /// <inheritdoc />
        protected override void WriteContents(IBinaryStreamWriter writer, ITypeCodedIndexProvider provider)
        {
            var x = new MarshalAsAttribute(UnmanagedType.Bool);

            writer.WriteByte((byte)NativeType);
            writer.WriteByte((byte)ArrayElementType);

            if (ParameterIndex.HasValue)
            {
                writer.WriteCompressedUInt32((uint)ParameterIndex.Value);
                if (NumberOfElements.HasValue)
                {
                    writer.WriteCompressedUInt32((uint)NumberOfElements.Value);
                    if (Flags.HasValue)
                    {
                        writer.WriteCompressedUInt32((uint)Flags.Value);
                    }
                }
            }
        }
Пример #16
0
        public override void Write(MetadataBuffer buffer, IBinaryStreamWriter writer)
        {
            writer.WriteSerString(TypeName);

            if (NamedArguments.Count == 0)
            {
                writer.WriteCompressedUInt32(1);
                writer.WriteCompressedUInt32(0);
            }
            else
            {
                writer.WriteCompressedUInt32(
                    (uint)(NamedArguments.Count.GetCompressedSize() + NamedArguments.Sum(x => x.GetPhysicalLength())));
                writer.WriteCompressedUInt32((uint)NamedArguments.Count);
                foreach (var argument in NamedArguments)
                {
                    argument.Write(buffer, writer);
                }
            }
        }
 /// <inheritdoc />
 protected override void WriteContents(IBinaryStreamWriter writer, ITypeCodedIndexProvider provider)
 {
     writer.WriteByte((byte)ElementType);
     writer.WriteByte((byte)(IsValueType ? ElementType.ValueType : ElementType.Class));
     TypeSignature.WriteTypeDefOrRef(writer, provider, GenericType);
     writer.WriteCompressedUInt32((uint)TypeArguments.Count);
     for (int i = 0; i < TypeArguments.Count; i++)
     {
         TypeArguments[i].Write(writer, provider);
     }
 }
Пример #18
0
        /// <inheritdoc />
        protected override void WriteContents(IBinaryStreamWriter writer, ITypeCodedIndexProvider provider)
        {
            writer.WriteByte((byte)Attributes);

            if (IsGeneric)
            {
                writer.WriteCompressedUInt32((uint)GenericParameterCount);
            }

            WriteParametersAndReturnType(writer, provider);
        }
Пример #19
0
        public override void Write(MetadataBuffer buffer, IBinaryStreamWriter writer)
        {
            writer.WriteByte((byte)ElementType);
            writer.WriteByte((byte)(IsValueType ? ElementType.ValueType : ElementType.Class));

            WriteTypeDefOrRef(buffer, writer, GenericType);

            writer.WriteCompressedUInt32((uint)GenericArguments.Count);
            foreach (var argument in GenericArguments)
            {
                argument.Write(buffer, writer);
            }
        }
Пример #20
0
        /// <summary>
        /// Writes an UTF8 string to the stream.
        /// </summary>
        /// <param name="writer">The writer to use.</param>
        /// <param name="value">The string to write.</param>
        public static void WriteSerString(this IBinaryStreamWriter writer, string value)
        {
            if (value == null)
            {
                writer.WriteByte(0xFF);
                return;
            }

            var bytes = Encoding.UTF8.GetBytes(value);

            writer.WriteCompressedUInt32((uint)bytes.Length);
            writer.WriteBytes(bytes);
        }
        /// <summary>
        /// Writes the security attribute to the provided output stream.
        /// </summary>
        /// <param name="writer">The output blob stream.</param>
        /// <param name="provider">The object to use for obtaining metadata tokens for members in the tables stream.</param>
        public void Write(IBinaryStreamWriter writer, ITypeCodedIndexProvider provider)
        {
            writer.WriteSerString(TypeNameBuilder.GetAssemblyQualifiedName(AttributeType));

            if (NamedArguments.Count == 0)
            {
                writer.WriteCompressedUInt32(1);
                writer.WriteCompressedUInt32(0);
            }
            else
            {
                using var subBlob = new MemoryStream();
                var subWriter = new BinaryStreamWriter(subBlob);

                subWriter.WriteCompressedUInt32((uint)NamedArguments.Count);
                foreach (var argument in NamedArguments)
                {
                    argument.Write(subWriter, provider);
                }

                writer.WriteCompressedUInt32((uint)subBlob.Length);
                writer.WriteBytes(subBlob.ToArray());
            }
        }
Пример #22
0
 internal static void WriteTypeDefOrRef(IBinaryStreamWriter writer, ITypeCodedIndexProvider provider, ITypeDefOrRef type)
 {
     writer.WriteCompressedUInt32(provider.GetTypeDefOrRefIndex(type));
 }
Пример #23
0
 protected static void WriteTypeDefOrRef(MetadataHeader header, IBinaryStreamWriter writer, ITypeDefOrRef type)
 {
     var encoder =
         header.GetStream<TableStream>()
             .GetIndexEncoder(CodedIndex.TypeDefOrRef);
     writer.WriteCompressedUInt32(encoder.EncodeToken(type.MetadataToken));
 }
Пример #24
0
 /// <inheritdoc />
 protected override void WriteContents(IBinaryStreamWriter writer, ITypeCodedIndexProvider provider)
 {
     writer.WriteByte((byte)ElementType);
     writer.WriteCompressedUInt32(provider.GetTypeDefOrRefIndex(Type));
 }
Пример #25
0
 public override void Write(MetadataBuffer buffer, IBinaryStreamWriter writer)
 {
     writer.WriteByte((byte)NativeType);
     writer.WriteCompressedUInt32((uint)NumberOfElements);
     writer.WriteByte((byte)ElementType);
 }
Пример #26
0
 /// <inheritdoc />
 protected override void WriteContents(IBinaryStreamWriter writer, ITypeCodedIndexProvider provider)
 {
     writer.WriteByte((byte)NativeType);
     writer.WriteCompressedUInt32((uint)Size);
 }
Пример #27
0
        /// <summary>
        /// Write a coded index to a type to the output stream.
        /// </summary>
        /// <param name="buffer">The metadata buffer to add the type to.</param>
        /// <param name="writer">The writer to use.</param>
        /// <param name="type">The type to write.</param>
        protected static void WriteTypeDefOrRef(MetadataBuffer buffer, IBinaryStreamWriter writer, ITypeDefOrRef type)
        {
            var encoder = buffer.TableStreamBuffer.GetIndexEncoder(CodedIndex.TypeDefOrRef);

            writer.WriteCompressedUInt32(encoder.EncodeToken(buffer.TableStreamBuffer.GetTypeToken(type)));
        }