void WriteType(IType type)
 {
     if (type == null)
     {
         helper.Error("Custom attribute: Type is null");
         WriteUTF8String(UTF8String.Empty);
     }
     else
     {
         WriteUTF8String(FullNameFactory.AssemblyQualifiedName(type, helper));
     }
 }
Пример #2
0
        byte[] Write(MarshalType marshalType)
        {
            if (marshalType is null)
            {
                return(null);
            }

            var type = marshalType.NativeType;

            if (type != NativeType.RawBlob)
            {
                if ((uint)type > byte.MaxValue)
                {
                    helper.Error("Invalid MarshalType.NativeType");
                }
                writer.WriteByte((byte)type);
            }
            bool canWrite = true;

            switch (type)
            {
            case NativeType.FixedSysString:
                var fixedSysString = (FixedSysStringMarshalType)marshalType;
                if (fixedSysString.IsSizeValid)
                {
                    WriteCompressedUInt32((uint)fixedSysString.Size);
                }
                break;

            case NativeType.SafeArray:
                var safeArray = (SafeArrayMarshalType)marshalType;
                if (UpdateCanWrite(safeArray.IsVariantTypeValid, "VariantType", ref canWrite))
                {
                    WriteCompressedUInt32((uint)safeArray.VariantType);
                }
                if (UpdateCanWrite(safeArray.IsUserDefinedSubTypeValid, "UserDefinedSubType", ref canWrite))
                {
                    Write(safeArray.UserDefinedSubType.AssemblyQualifiedName);
                }
                break;

            case NativeType.FixedArray:
                var fixedArray = (FixedArrayMarshalType)marshalType;
                if (UpdateCanWrite(fixedArray.IsSizeValid, "Size", ref canWrite))
                {
                    WriteCompressedUInt32((uint)fixedArray.Size);
                }
                if (UpdateCanWrite(fixedArray.IsElementTypeValid, "ElementType", ref canWrite))
                {
                    WriteCompressedUInt32((uint)fixedArray.ElementType);
                }
                break;

            case NativeType.Array:
                var array = (ArrayMarshalType)marshalType;
                if (UpdateCanWrite(array.IsElementTypeValid, "ElementType", ref canWrite))
                {
                    WriteCompressedUInt32((uint)array.ElementType);
                }
                if (UpdateCanWrite(array.IsParamNumberValid, "ParamNumber", ref canWrite))
                {
                    WriteCompressedUInt32((uint)array.ParamNumber);
                }
                if (UpdateCanWrite(array.IsSizeValid, "Size", ref canWrite))
                {
                    WriteCompressedUInt32((uint)array.Size);
                }
                if (UpdateCanWrite(array.IsFlagsValid, "Flags", ref canWrite))
                {
                    WriteCompressedUInt32((uint)array.Flags);
                }
                break;

            case NativeType.CustomMarshaler:
                var custMarshaler = (CustomMarshalType)marshalType;
                Write(custMarshaler.Guid);
                Write(custMarshaler.NativeTypeName);
                var cm     = custMarshaler.CustomMarshaler;
                var cmName = cm is null ? string.Empty : FullNameFactory.AssemblyQualifiedName(cm, this);
                Write(cmName);
                Write(custMarshaler.Cookie);
                break;

            case NativeType.IUnknown:
            case NativeType.IDispatch:
            case NativeType.IntF:
                var iface = (InterfaceMarshalType)marshalType;
                if (iface.IsIidParamIndexValid)
                {
                    WriteCompressedUInt32((uint)iface.IidParamIndex);
                }
                break;

            case NativeType.RawBlob:
                var data = ((RawMarshalType)marshalType).Data;
                if (data is not null)
                {
                    writer.WriteBytes(data);
                }
                break;

            default:
                break;
            }

            return(outStream.ToArray());
        }