void WriteType(IType type)
 {
     if (type == null)
     {
         helper.Error("Type is null");
         WriteUTF8String(UTF8String.Empty);
     }
     else
     {
         WriteUTF8String(FullNameCreator.AssemblyQualifiedName(type, helper));
     }
 }
Example #2
0
        private byte[] Write(MarshalType marshalType)
        {
            if (marshalType == null)
            {
                return(null);
            }

            var type = marshalType.NativeType;

            if (type != NativeType.RawBlob)
            {
                if ((uint)type > byte.MaxValue)
                {
                    helper.Error("Invalid MarshalType.NativeType");
                }
                writer.Write((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 == null ? string.Empty : FullNameCreator.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 != null)
                {
                    writer.Write(data);
                }
                break;

            default:
                break;
            }

            writer.Flush();
            return(outStream.ToArray());
        }