/// <summary> /// Reads a single fixed array marshal descriptor from the provided input stream. /// </summary> /// <param name="reader">The input stream.</param> /// <returns>The descriptor.</returns> public static FixedArrayMarshalDescriptor FromReader(IBinaryStreamReader reader) { var result = new FixedArrayMarshalDescriptor(); if (reader.TryReadCompressedUInt32(out uint value)) { result.Size = (int)value; if (reader.TryReadCompressedUInt32(out value)) { result.ArrayElementType = (NativeType)value; } } return(result); }
/// <summary> /// Reads a marshal descriptor signature from the provided input stream. /// </summary> /// <param name="parentModule">The module that defines the marshal descriptor</param> /// <param name="reader">The input stream.</param> /// <returns>The marshal descriptor.</returns> public static MarshalDescriptor FromReader(ModuleDefinition parentModule, ref BinaryStreamReader reader) { var nativeType = (NativeType)reader.ReadByte(); MarshalDescriptor descriptor = nativeType switch { NativeType.SafeArray => SafeArrayMarshalDescriptor.FromReader(parentModule, ref reader), NativeType.FixedArray => FixedArrayMarshalDescriptor.FromReader(ref reader), NativeType.LPArray => LPArrayMarshalDescriptor.FromReader(ref reader), NativeType.CustomMarshaller => CustomMarshalDescriptor.FromReader(parentModule, ref reader), NativeType.FixedSysString => FixedSysStringMarshalDescriptor.FromReader(ref reader), NativeType.Interface => ComInterfaceMarshalDescriptor.FromReader(nativeType, ref reader), NativeType.IDispatch => ComInterfaceMarshalDescriptor.FromReader(nativeType, ref reader), NativeType.IUnknown => ComInterfaceMarshalDescriptor.FromReader(nativeType, ref reader), _ => new SimpleMarshalDescriptor(nativeType) }; descriptor.ExtraData = reader.ReadToEnd(); return(descriptor); }