/// <inheritdoc />
 protected override void WriteContents(IBinaryStreamWriter writer, ITypeCodedIndexProvider provider)
 {
     writer.WriteByte((byte)NativeType);
     writer.WriteSerString(Guid ?? string.Empty);
     writer.WriteSerString(NativeTypeName ?? string.Empty);
     writer.WriteSerString(MarshalType is null ? string.Empty : TypeNameBuilder.GetAssemblyQualifiedName(MarshalType));
     writer.WriteSerString(Cookie ?? string.Empty);
 }
Пример #2
0
 public override void Write(MetadataBuffer buffer, IBinaryStreamWriter writer)
 {
     writer.WriteByte((byte)NativeType);
     writer.WriteSerString(Guid.ToString("B"));
     writer.WriteSerString(UnmanagedType);
     writer.WriteSerString(ManagedType);
     writer.WriteSerString(Cookie);
 }
 /// <summary>
 /// Writes the named argument to the provided output stream.
 /// </summary>
 /// <param name="writer">The output 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.WriteByte((byte)MemberType);
     TypeSignature.WriteFieldOrPropType(writer, ArgumentType);
     writer.WriteSerString(MemberName);
     Argument.Write(writer, provider);
 }
Пример #4
0
 public override void Write(MetadataBuffer buffer, IBinaryStreamWriter writer)
 {
     writer.WriteByte((byte)ArgumentMemberType);
     ArgumentType.Write(buffer, writer); // TODO: write FieldOrPropType instead.
     writer.WriteSerString(MemberName);
     Argument.Write(buffer, writer);
 }
Пример #5
0
        internal static void WriteFieldOrPropType(IBinaryStreamWriter writer, TypeSignature type)
        {
            switch (type.ElementType)
            {
            case ElementType.Boolean:
            case ElementType.Char:
            case ElementType.I1:
            case ElementType.U1:
            case ElementType.I2:
            case ElementType.U2:
            case ElementType.I4:
            case ElementType.U4:
            case ElementType.I8:
            case ElementType.U8:
            case ElementType.R4:
            case ElementType.R8:
            case ElementType.I:
            case ElementType.U:
            case ElementType.String:
                writer.WriteByte((byte)type.ElementType);
                break;

            case ElementType.Object:
                writer.WriteByte((byte)ElementType.Boxed);

                break;

            case ElementType.SzArray:
                writer.WriteByte((byte)ElementType.SzArray);

                var arrayType = (SzArrayTypeSignature)type;
                WriteFieldOrPropType(writer, arrayType.BaseType);
                break;

            default:
                if (type.IsTypeOf("System", "Type"))
                {
                    writer.WriteByte((byte)ElementType.Type);
                    return;
                }

                var typeDef = type.Resolve();
                if (typeDef != null && typeDef.IsEnum)
                {
                    writer.WriteByte((byte)ElementType.Enum);
                    writer.WriteSerString(TypeNameBuilder.GetAssemblyQualifiedName(type));
                    return;
                }

                throw new ArgumentOutOfRangeException();
            }
        }
Пример #6
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);
                }
            }
        }
        /// <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());
            }
        }
Пример #8
0
        private void WriteValue(IBinaryStreamWriter writer, TypeSignature argumentType, ITypeCodedIndexProvider provider, object value)
        {
            if (argumentType.IsTypeOf("System", "Type"))
            {
                writer.WriteSerString(TypeNameBuilder.GetAssemblyQualifiedName((TypeSignature)value));
                return;
            }

            switch (argumentType.ElementType)
            {
            case ElementType.Boolean:
                writer.WriteByte((byte)((bool)value ? 1 : 0));
                break;

            case ElementType.Char:
                writer.WriteUInt16((char)value);
                break;

            case ElementType.I1:
                writer.WriteSByte((sbyte)value);
                break;

            case ElementType.U1:
                writer.WriteByte((byte)value);
                break;

            case ElementType.I2:
                writer.WriteInt16((short)value);
                break;

            case ElementType.U2:
                writer.WriteUInt16((ushort)value);
                break;

            case ElementType.I4:
                writer.WriteInt32((int)value);
                break;

            case ElementType.U4:
                writer.WriteUInt32((uint)value);
                break;

            case ElementType.I8:
                writer.WriteInt64((long)value);
                break;

            case ElementType.U8:
                writer.WriteUInt64((ulong)value);
                break;

            case ElementType.R4:
                writer.WriteSingle((float)value);
                break;

            case ElementType.R8:
                writer.WriteDouble((double)value);
                break;

            case ElementType.String:
                writer.WriteSerString(value as string);
                break;

            case ElementType.Object:
                var valueType    = value.GetType();
                var innerTypeSig = argumentType.Module.CorLibTypeFactory.FromName(valueType.Namespace, valueType.Name);
                TypeSignature.WriteFieldOrPropType(writer, innerTypeSig);
                WriteValue(writer, innerTypeSig, provider, value);
                break;

            case ElementType.Class:
            case ElementType.Enum:
            case ElementType.ValueType:
                var enumTypeDef = argumentType.Resolve();
                if (enumTypeDef != null && enumTypeDef.IsEnum)
                {
                    WriteValue(writer, enumTypeDef.GetEnumUnderlyingType(), provider, Value);
                }
                else
                {
                    throw new NotImplementedException();
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #9
0
        /// <inheritdoc />
        public override void Write(MetadataBuffer buffer, IBinaryStreamWriter writer)
        {
            if (Value == null)
            {
                writer.WriteSerString(null);
                return;
            }

            switch (Type.GetTypeCode(Value.GetType()))
            {
            case TypeCode.Boolean:
                writer.WriteByte((byte)((bool)Value ? 1 : 0));
                break;

            case TypeCode.Byte:
                writer.WriteByte((byte)Value);
                break;

            case TypeCode.Char:
                writer.WriteUInt16((char)Value);
                break;

            case TypeCode.Double:
                writer.WriteDouble((double)Value);
                break;

            case TypeCode.Int16:
                writer.WriteInt16((short)Value);
                break;

            case TypeCode.Int32:
                writer.WriteInt32((int)Value);
                break;

            case TypeCode.Int64:
                writer.WriteInt64((long)Value);
                break;

            case TypeCode.SByte:
                writer.WriteSByte((sbyte)Value);
                break;

            case TypeCode.Single:
                writer.WriteSingle((float)Value);
                break;

            case TypeCode.String:
                writer.WriteSerString((string)Value);
                break;

            case TypeCode.UInt16:
                writer.WriteUInt16((ushort)Value);
                break;

            case TypeCode.UInt32:
                writer.WriteUInt32((uint)Value);
                break;

            case TypeCode.UInt64:
                writer.WriteUInt64((ulong)Value);
                break;

            default:
                if (Value is TypeSignature typeSignature)
                {
                    writer.WriteSerString(TypeNameBuilder.GetAssemblyQualifiedName(typeSignature));
                }
                else
                {
                    throw new NotSupportedException();
                }
                break;
            }
        }