public ParameterDefinition(string name, ParameterAttributes attributes, object defaultValue, MarshalInfo marshal) { Name = name; Attributes = attributes; DefaultValue = defaultValue; Marshal = marshal; }
internal static string BuildMethodParameterList(MethodReference interopMethod, MethodReference interfaceMethod, Unity.IL2CPP.ILPreProcessor.TypeResolver typeResolver, MarshalType marshalType, bool includeTypeNames) { List <string> elements = new List <string>(); int num = 0; foreach (ParameterDefinition definition in interopMethod.Parameters) { MarshalInfo marshalInfo = interfaceMethod.Parameters[num].MarshalInfo; DefaultMarshalInfoWriter writer = MarshalDataCollector.MarshalInfoWriterFor(typeResolver.Resolve(definition.ParameterType), marshalType, marshalInfo, true, false, false, null); foreach (MarshaledType type in writer.MarshaledTypes) { elements.Add(string.Format(!includeTypeNames ? "{1}" : "{0} {1}", type.DecoratedName, Naming.ForParameterName(definition) + type.VariableName)); } num++; } TypeReference reference2 = typeResolver.Resolve(interopMethod.ReturnType); if (reference2.MetadataType != MetadataType.Void) { MarshalInfo info2 = interfaceMethod.MethodReturnType.MarshalInfo; MarshaledType[] marshaledTypes = MarshalDataCollector.MarshalInfoWriterFor(reference2, marshalType, info2, true, false, false, null).MarshaledTypes; for (int i = 0; i < (marshaledTypes.Length - 1); i++) { elements.Add(string.Format(!includeTypeNames ? "{1}" : "{0}* {1}", marshaledTypes[i].DecoratedName, Naming.ForComInterfaceReturnParameterName() + marshaledTypes[i].VariableName)); } elements.Add(string.Format(!includeTypeNames ? "{1}" : "{0}* {1}", marshaledTypes[marshaledTypes.Length - 1].DecoratedName, Naming.ForComInterfaceReturnParameterName())); } return(elements.AggregateWithComma()); }
protected ArrayMarshalInfoWriter(ArrayType type, MarshalType marshalType, MarshalInfo marshalInfo) : base(type) { this._marshalInfo = marshalInfo; this._marshalType = marshalType; this._arrayType = type; this._elementType = type.ElementType; MarshalInfo info = null; ArrayMarshalInfo info2 = marshalInfo as ArrayMarshalInfo; FixedArrayMarshalInfo info3 = marshalInfo as FixedArrayMarshalInfo; this._arraySize = 1; this._nativeElementType = NativeType.None; if (info2 != null) { this._arraySize = info2.Size; this._sizeParameterIndex = info2.SizeParameterIndex; if ((this._arraySize == 0) || ((this._arraySize == -1) && (this._sizeParameterIndex >= 0))) { this._arraySizeSelection = ArraySizeOptions.UseSizeParameterIndex; } else { this._arraySizeSelection = ArraySizeOptions.UseArraySize; } this._nativeElementType = info2.ElementType; info = new MarshalInfo(this._nativeElementType); } else if (info3 != null) { this._arraySize = info3.Size; this._nativeElementType = info3.ElementType; info = new MarshalInfo(this._nativeElementType); } if (this._arraySize == -1) { this._arraySize = 1; } this._elementTypeMarshalInfoWriter = MarshalDataCollector.MarshalInfoWriterFor(this._elementType, marshalType, info, false, false, true, null); if (this._elementTypeMarshalInfoWriter.MarshaledTypes.Length > 1) { throw new InvalidOperationException($"ArrayMarshalInfoWriter cannot marshal arrays of {this._elementType.FullName}."); } this._arrayMarshaledTypeName = this._elementTypeMarshalInfoWriter.MarshaledTypes[0].DecoratedName + "*"; if (marshalType == MarshalType.WindowsRuntime) { string name = DefaultMarshalInfoWriter.Naming.ForVariable(DefaultMarshalInfoWriter.TypeProvider.UInt32TypeReference); this._arraySizeSelection = ArraySizeOptions.UseFirstMarshaledType; this._marshaledTypes = new MarshaledType[] { new MarshaledType(name, name, "ArraySize"), new MarshaledType(this._arrayMarshaledTypeName, this._arrayMarshaledTypeName) }; } else { this._marshaledTypes = new MarshaledType[] { new MarshaledType(this._arrayMarshaledTypeName, this._arrayMarshaledTypeName) }; } StringMarshalInfoWriter writer = this._elementTypeMarshalInfoWriter as StringMarshalInfoWriter; if (writer != null) { this._nativeElementType = writer.NativeType; } }
public static string GetTextualRepresentation(this MarshalInfo marshalInfo, Action <string> appendAction, TextualRepresentationOptions options) { if (marshalInfo == null) { return(string.Empty); } return(marshalInfo.NativeType.ToString()); }
public static MarshalInfo GetMarshalInfo( this IMarshalInfoProvider self, ref MarshalInfo variable, ModuleDefinition module) { return(module.HasImage() ? module.Read(ref variable, self, (provider, reader) => reader.ReadMarshalInfo(provider)) : null); }
public static MarshalInfo GetMarshalInfo( IMarshalInfoProvider self, ref MarshalInfo variable, ModuleDefinition module) { return Mixin.HasImage(module) ? module.Read(ref variable, self, (provider, reader) => reader.ReadMarshalInfo(provider)) : null; }
private void ProcessMarshallInfo(MarshalInfo marshalInfo) { var customMarshalInfo = marshalInfo as CustomMarshalInfo; if (customMarshalInfo != null) { AddType(customMarshalInfo.ManagedType); } }
public static MarshalInfo GetMarshalInfo( this IMarshalInfoProvider self, /*Telerik Authorship*/ ref MarshalInfo variable, ModuleDefinition module) { /*Telerik Authorship*/ return module.HasImage () ? module.Read (ref variable, self, (provider, reader) => reader.ReadMarshalInfo (provider)) : null; }
/// <summary> /// Get <see cref="MarshalInfo"/> for the <see cref="MethodReturnType"/> instance. /// </summary> /// <param name="self">The <see cref="MethodReturnType"/> instance.</param> /// <param name="marshalInfo">Returned <see cref="MarshalInfo"/> instance.</param> /// <returns>Returns true if exceptions haven't occurred; otherwise false.</returns> public static bool TryGetMarshalInfo(this IMarshalInfoProvider self, out MarshalInfo marshalInfo) { try { marshalInfo = self.MarshalInfo; return(true); } catch { marshalInfo = null; return(false); } }
/// <summary> /// Check arguments of custom attributes of a method for the return type. /// </summary> /// <param name="returnType">The method return type.</param> private void CheckMethodReturnAttributes(MethodReturnType returnType) { if (returnType.HasCustomAttributes) { var customAttributeArgs = returnType.CustomAttributes.SelectMany(ca => GetCustomAttributeArgument(ca)); CheckCustomAttributes(customAttributeArgs); } MarshalInfo marshalInfo = null; bool hasMarshalInfo = returnType.HasMarshalInfo && returnType.TryGetMarshalInfo(out marshalInfo); if (hasMarshalInfo && marshalInfo != null) { CheckMarshalInfo(marshalInfo); } }
/// <summary> /// Check marshal info. Nees to resolve type reference if marshal is CustomMarshaller /// </summary> /// <param name="marshalInfo">The marshal inforamtion.</param> private void CheckMarshalInfo(MarshalInfo marshalInfo) { var cmi = marshalInfo as CustomMarshalInfo; if (cmi != null && cmi.ManagedType != null) { IMetadataScope forwardedFrom; var typeDef = cmi.ManagedType.Resolve(out forwardedFrom); _sharedData.RemoveFromCandidates(forwardedFrom); if (typeDef != null) { _sharedData.RemoveFromCandidates(typeDef.Scope); _sharedData.AddToUsedTypes(typeDef.AssemblyQualifiedName()); } } }
public ComSafeArrayMarshalInfoWriter(ArrayType type, MarshalInfo marshalInfo) : base(type) { this._elementType = type.ElementType; this._marshalInfo = marshalInfo as SafeArrayMarshalInfo; if (this._marshalInfo == null) { throw new InvalidOperationException($"SafeArray type '{type.FullName}' has invalid MarshalAsAttribute."); } if ((this._marshalInfo.ElementType == VariantType.BStr) && (this._elementType.MetadataType != MetadataType.String)) { throw new InvalidOperationException($"SafeArray(BSTR) type '{type.FullName}' has invalid MarshalAsAttribute."); } NativeType nativeElementType = this.GetNativeElementType(); this._elementTypeMarshalInfoWriter = MarshalDataCollector.MarshalInfoWriterFor(this._elementType, MarshalType.COM, new MarshalInfo(nativeElementType), false, false, false, null); string name = $"Il2CppSafeArray/*{this._marshalInfo.ElementType.ToString().ToUpper()}*/*"; this._marshaledTypes = new MarshaledType[] { new MarshaledType(name, name) }; }
private void EmitMarshalInfo( MethodReference methodRef, MethodDefinition method, Mono.Cecil.ParameterAttributes attributes, MarshalInfo mi, IAstEmitter astEmitter ) { Formatter.OpenBrace(); if (mi.NativeType == NativeType.CustomMarshaler) { var cmi = (CustomMarshalInfo)mi; Formatter.WriteRaw("CustomMarshaler: "); Formatter.TypeReference(cmi.ManagedType, astEmitter.ReferenceContext); if (cmi.Cookie != null) { Formatter.Comma(); Formatter.WriteRaw("Cookie: "); Formatter.Value(cmi.Cookie); } } else { Formatter.WriteRaw("NativeType: "); Formatter.Value(mi.NativeType.ToString()); } if (attributes.HasFlag(Mono.Cecil.ParameterAttributes.Out)) { Formatter.Comma(); Formatter.NewLine(); Formatter.WriteRaw("Out: true"); Formatter.NewLine(); } else { Formatter.NewLine(); } Formatter.CloseBrace(false); }
/// <summary> /// Check fields' attributes. /// </summary> /// <param name="typeDef">The type definition which will be investigated.</param> private void CheckFields(TypeDefinition typeDef) { var fields = typeDef.Fields.Where(f => f.HasCustomAttributes || f.HasMarshalInfo); foreach (var field in fields) { CheckFieldCustomAttributes(field); if (!_sharedData.HasCandidateReferences) { return; } MarshalInfo marshalInfo = null; field.TryGetMarshalInfo(out marshalInfo); CheckMarshalInfo(marshalInfo); if (!_sharedData.HasCandidateReferences) { return; } } }
public StringMarshalInfoWriter(TypeReference type, MarshalType marshalType, MarshalInfo marshalInfo, bool useUnicodeCharSet, bool forByReferenceType, bool forFieldMarshaling) : base(type) { this._isStringBuilder = MarshalingUtils.IsStringBuilder(type); this._useUnicodeCharSet = useUnicodeCharSet; this._nativeType = DetermineNativeTypeFor(marshalType, marshalInfo, this._useUnicodeCharSet, this._isStringBuilder); if (this._nativeType == (Mono.Cecil.NativeType.Error | Mono.Cecil.NativeType.Boolean)) { this._marshaledTypeName = "Il2CppHString"; } else if (this.IsWideString) { this._marshaledTypeName = "Il2CppChar*"; } else { this._marshaledTypeName = "char*"; } this._marshaledTypes = new MarshaledType[] { new MarshaledType(this._marshaledTypeName, this._marshaledTypeName) }; this._marshalInfo = marshalInfo; this._canReferenceOriginalManagedString = ((!this._isStringBuilder && !forByReferenceType) && !forFieldMarshaling) && ((this._nativeType == Mono.Cecil.NativeType.LPWStr) || (this._nativeType == (Mono.Cecil.NativeType.Error | Mono.Cecil.NativeType.Boolean))); }
/// <summary> /// Determines whether the specified value type is blittable. /// </summary> /// <param name="typeReference">The type reference.</param> /// <param name="marshalInfo">The marshal information.</param> /// <returns></returns> private static bool IsValueTypeBlittable(TypeReference typeReference, MarshalInfo marshalInfo) { bool isBlittable; if (blittableValueTypes.TryGetValue(typeReference, out isBlittable)) { return(isBlittable); } var typeDefinition = typeReference.Resolve(); // Only value types are blittable if (typeDefinition.IsValueType) { isBlittable = true; if (!typeDefinition.IsEnum && !typeDefinition.IsExplicitLayout) { // Check if every field is blittable foreach (var field in typeDefinition.Fields) { if (field.IsStatic) { continue; } var fieldType = ResolveGenericsVisitor.Process(typeReference, field.FieldType); if (!IsBlittable(fieldType, field.HasMarshalInfo ? field.MarshalInfo : null)) { isBlittable = false; break; } } } } blittableValueTypes[typeReference] = isBlittable; return(isBlittable); }
/// <summary> /// Determines whether the specified type is blittable. /// </summary> /// <param name="typeReference">The type reference.</param> /// <param name="marshalInfo">The marshal information.</param> /// <returns></returns> private static bool IsBlittable(TypeReference typeReference, MarshalInfo marshalInfo) { switch (typeReference.MetadataType) { case MetadataType.ValueType: case MetadataType.Class: return(IsValueTypeBlittable(typeReference, marshalInfo)); case MetadataType.SByte: case MetadataType.Byte: case MetadataType.Int16: case MetadataType.UInt16: case MetadataType.Int32: case MetadataType.UInt32: case MetadataType.Int64: case MetadataType.UInt64: case MetadataType.Single: case MetadataType.Double: case MetadataType.IntPtr: case MetadataType.UIntPtr: case MetadataType.Pointer: case MetadataType.Char: return(true); case MetadataType.Boolean: if (marshalInfo != null) { // I1/U1 boolean need marshalling if (marshalInfo.NativeType == NativeType.I1 || marshalInfo.NativeType == NativeType.U1) { return(false); } } return(true); default: return(false); } }
public IntPtr MarshalManagedToNative(object managedObj) { if (managedObj == null) { return(IntPtr.Zero); } if (!(managedObj is byte[][])) { throw new MarshalDirectiveException("This custom marshaler must be used on a double[][]."); } Array[] array = (Array[])managedObj; MarshalInfo mi = new MarshalInfo(); mi.InnerArrayPointers = new IntPtr[array.Length]; mi.InnerArrayPointersHandle = GCHandle.Alloc(mi.InnerArrayPointers, GCHandleType.Pinned); mi.InnerArrayHandles = new GCHandle[array.Length]; for (int i = 0; i < array.Length; i++) { mi.InnerArrayHandles[i] = GCHandle.Alloc(array[i], GCHandleType.Pinned); mi.InnerArrayPointers[i] = mi.InnerArrayHandles[i].AddrOfPinnedObject(); } IntPtr pointer = mi.InnerArrayPointersHandle.AddrOfPinnedObject(); lock (marshalMap) { marshalMap.Add(pointer, mi); } return(pointer); }
/// <summary> /// Finds the marshaller for given <see cref="TypeReference"/> and <see cref="MarshalInfo"/>. /// </summary> /// <param name="type">The type.</param> /// <param name="marshalInfo">The marshal information.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"> /// </exception> public static Marshaller FindMarshallerForType(TypeReference type, MarshalInfo marshalInfo) { // First, check the cache // TODO: Take marshalInfo into account Marshaller marshaller; if (marshallers.TryGetValue(type, out marshaller)) { return(marshaller); } if (marshalInfo != null) { switch (marshalInfo.NativeType) { case NativeType.IUnknown: case NativeType.IntF: // TODO: Implement a real marshaller for that case return(new BlittableMarshaller()); } } switch (type.MetadataType) { case MetadataType.Object: case MetadataType.ValueType: case MetadataType.Class: { // Various types with specific marshallers if (type.FullName == typeof(HandleRef).FullName) { marshaller = new HandleRefMarshaller(); break; } if (type.FullName == typeof(StringBuilder).FullName) { marshaller = new StringBuilderMarshaller(); break; } if (type.FullName == typeof(string).FullName) { marshaller = new StringMarshaller(marshalInfo); break; } var typeDefinition = type.Resolve(); // Check if type is a delegate if (typeDefinition.BaseType != null && typeDefinition.BaseType.FullName == typeof(MulticastDelegate).FullName) { marshaller = new DelegateMarshaller(); break; } // Check if type is a reference type if (!typeDefinition.IsValueType) { return(new BlittableMarshaller()); } if (typeDefinition.IsEnum) { return(new BlittableMarshaller()); } // Check if type is blittable if (IsBlittable(type, marshalInfo)) { marshaller = new BlittableMarshaller(); break; } marshaller = new StructMarshaller(type); break; } case MetadataType.Boolean: if (marshalInfo != null) { // I1/U1 boolean don't need any marshalling if (marshalInfo.NativeType == NativeType.I1 || marshalInfo.NativeType == NativeType.U1) { marshaller = new BlittableMarshaller(); } else { throw new NotImplementedException(); } } else { // Default case: 4-byte integer marshaller = new BooleanMarshaller(); } break; case MetadataType.SByte: case MetadataType.Byte: case MetadataType.Int16: case MetadataType.UInt16: case MetadataType.Int32: case MetadataType.UInt32: case MetadataType.Int64: case MetadataType.UInt64: case MetadataType.Single: case MetadataType.Double: case MetadataType.IntPtr: case MetadataType.UIntPtr: case MetadataType.Pointer: case MetadataType.Char: marshaller = new BlittableMarshaller(); break; case MetadataType.String: marshaller = new StringMarshaller(marshalInfo); break; case MetadataType.Array: { var elementType = ((ArrayType)type).ElementType; if (IsBlittable(elementType, marshalInfo)) { marshaller = new BlittableArrayMarshaller(); break; } marshaller = new ArrayMarshaller(FindMarshallerForType(elementType, marshalInfo)); break; } default: throw new NotImplementedException(string.Format("Marshaller for type {0}", type)); } marshallers[type] = marshaller; return(marshaller); }
public void VisitMarshalSpec(MarshalInfo marshalInfo) { }
public ByReferenceMarshalInfoWriter(ByReferenceType type, MarshalType marshalType, MarshalInfo marshalInfo) : base(type) { this._elementType = type.ElementType; this._elementTypeMarshalInfoWriter = MarshalDataCollector.MarshalInfoWriterFor(type.ElementType, marshalType, marshalInfo, false, true, false, null); if (< > f__am$cache0 == null) {
public LPArrayMarshalInfoWriter(ArrayType arrayType, MarshalType marshalType, MarshalInfo marshalInfo) : base(arrayType, marshalType, marshalInfo) { }
private static DefaultMarshalInfoWriter CreateMarshalInfoWriter(TypeReference type, MarshalType marshalType, MarshalInfo marshalInfo, bool useUnicodeCharSet, bool forByReferenceType, bool forFieldMarshaling, HashSet <TypeReference> typesForRecursiveFields) {
private MarshalInfo CopyMarshalInfo(MarshalInfo info) { return(info == null ? null : new MarshalInfo(info.NativeType)); }
public StringMarshaller(MarshalInfo marshalInfo) { nativeType = marshalInfo != null ? marshalInfo.NativeType : NativeType.LPTStr; }
public virtual void VisitMarshalSpec(MarshalInfo MarshalInfo) { }
public ComObjectMarshalInfoWriter(TypeReference type, MarshalType marshalType, MarshalInfo marshalInfo) : base(type) { this._marshalAsInspectable = (marshalType == MarshalType.WindowsRuntime) || ((marshalInfo != null) && (marshalInfo.NativeType == (NativeType.CustomMarshaler | NativeType.Boolean))); TypeDefinition definition = type.Resolve(); this._isSealed = definition.IsSealed; this._isClass = ((marshalType == MarshalType.WindowsRuntime) && !definition.IsInterface()) && !type.IsSystemObject(); this._defaultInterface = !this._isClass ? type : definition.ExtractDefaultInterface(); this._managedTypeName = !this._isClass ? DefaultMarshalInfoWriter.Naming.ForTypeNameOnly(DefaultMarshalInfoWriter.TypeProvider.SystemObject) : DefaultMarshalInfoWriter.Naming.ForTypeNameOnly(type); if (type.IsSystemObject()) { this._interfaceTypeName = !this._marshalAsInspectable ? "Il2CppIUnknown" : "Il2CppIInspectable"; } else { this._interfaceTypeName = DefaultMarshalInfoWriter.Naming.ForTypeNameOnly(this._defaultInterface); } this._marshaledTypes = new MarshaledType[] { new MarshaledType(this._interfaceTypeName + '*', this._interfaceTypeName + '*') }; }
public BlittableByReferenceMarshalInfoWriter(ByReferenceType type, MarshalType marshalType, MarshalInfo marshalInfo) : base(type) { this._elementType = type.ElementType; this._elementTypeMarshalInfoWriter = MarshalDataCollector.MarshalInfoWriterFor(this._elementType, marshalType, marshalInfo, false, true, false, null); if (this._elementTypeMarshalInfoWriter.MarshaledTypes.Length > 1) { throw new InvalidOperationException($"BlittableByReferenceMarshalInfoWriter cannot marshal {type.ElementType.FullName}&."); } this._marshaledTypes = new MarshaledType[] { new MarshaledType(this._elementTypeMarshalInfoWriter.MarshaledTypes[0].Name + "*", this._elementTypeMarshalInfoWriter.MarshaledTypes[0].DecoratedName + "*") }; }
private static Mono.Cecil.NativeType DetermineNativeTypeFor(MarshalType marshalType, MarshalInfo marshalInfo, bool useUnicodeCharset, bool isStringBuilder) { Mono.Cecil.NativeType nativeType; if (marshalInfo != null) { nativeType = marshalInfo.NativeType; } else if (marshalType == MarshalType.PInvoke) { nativeType = !useUnicodeCharset ? Mono.Cecil.NativeType.LPStr : Mono.Cecil.NativeType.LPWStr; } else { nativeType = Mono.Cecil.NativeType.None; } bool flag = false; switch (nativeType) { case Mono.Cecil.NativeType.BStr: case Mono.Cecil.NativeType.LPStr: case Mono.Cecil.NativeType.LPWStr: case Mono.Cecil.NativeType.FixedSysString: case (Mono.Cecil.NativeType.Error | Mono.Cecil.NativeType.Boolean): flag = true; break; } if (flag && ((!isStringBuilder || (nativeType == Mono.Cecil.NativeType.LPStr)) || (nativeType == Mono.Cecil.NativeType.LPWStr))) { return(nativeType); } if (marshalType != MarshalType.PInvoke) { if (marshalType != MarshalType.COM) { if (marshalType != MarshalType.WindowsRuntime) { return(nativeType); } return(Mono.Cecil.NativeType.Error | Mono.Cecil.NativeType.Boolean); } } else { return(Mono.Cecil.NativeType.LPStr); } return(Mono.Cecil.NativeType.BStr); }
void WriteNativeType(NativeType nativeType, MarshalInfo marshalInfo = null) { switch (nativeType) { case NativeType.None: break; case NativeType.Boolean: output.Write("bool"); break; case NativeType.I1: output.Write("int8"); break; case NativeType.U1: output.Write("unsigned int8"); break; case NativeType.I2: output.Write("int16"); break; case NativeType.U2: output.Write("unsigned int16"); break; case NativeType.I4: output.Write("int32"); break; case NativeType.U4: output.Write("unsigned int32"); break; case NativeType.I8: output.Write("int64"); break; case NativeType.U8: output.Write("unsigned int64"); break; case NativeType.R4: output.Write("float32"); break; case NativeType.R8: output.Write("float64"); break; case NativeType.LPStr: output.Write("lpstr"); break; case NativeType.Int: output.Write("int"); break; case NativeType.UInt: output.Write("unsigned int"); break; case NativeType.Func: goto default; // ?? case NativeType.Array: ArrayMarshalInfo ami = (ArrayMarshalInfo)marshalInfo; if (ami == null) { goto default; } if (ami.ElementType != NativeType.Max) { WriteNativeType(ami.ElementType); } output.Write('['); if (ami.SizeParameterMultiplier == 0) { output.Write(ami.Size.ToString()); } else { if (ami.Size >= 0) { output.Write(ami.Size.ToString()); } output.Write(" + "); output.Write(ami.SizeParameterIndex.ToString()); } output.Write(']'); break; case NativeType.Currency: output.Write("currency"); break; case NativeType.BStr: output.Write("bstr"); break; case NativeType.LPWStr: output.Write("lpwstr"); break; case NativeType.LPTStr: output.Write("lptstr"); break; case NativeType.FixedSysString: output.Write("fixed sysstring[{0}]", ((FixedSysStringMarshalInfo)marshalInfo).Size); break; case NativeType.IUnknown: output.Write("iunknown"); break; case NativeType.IDispatch: output.Write("idispatch"); break; case NativeType.Struct: output.Write("struct"); break; case NativeType.IntF: output.Write("interface"); break; case NativeType.SafeArray: output.Write("safearray "); SafeArrayMarshalInfo sami = marshalInfo as SafeArrayMarshalInfo; if (sami != null) { switch (sami.ElementType) { case VariantType.None: break; case VariantType.I2: output.Write("int16"); break; case VariantType.I4: output.Write("int32"); break; case VariantType.R4: output.Write("float32"); break; case VariantType.R8: output.Write("float64"); break; case VariantType.CY: output.Write("currency"); break; case VariantType.Date: output.Write("date"); break; case VariantType.BStr: output.Write("bstr"); break; case VariantType.Dispatch: output.Write("idispatch"); break; case VariantType.Error: output.Write("error"); break; case VariantType.Bool: output.Write("bool"); break; case VariantType.Variant: output.Write("variant"); break; case VariantType.Unknown: output.Write("iunknown"); break; case VariantType.Decimal: output.Write("decimal"); break; case VariantType.I1: output.Write("int8"); break; case VariantType.UI1: output.Write("unsigned int8"); break; case VariantType.UI2: output.Write("unsigned int16"); break; case VariantType.UI4: output.Write("unsigned int32"); break; case VariantType.Int: output.Write("int"); break; case VariantType.UInt: output.Write("unsigned int"); break; default: output.Write(sami.ElementType.ToString()); break; } } break; case NativeType.FixedArray: output.Write("fixed array"); FixedArrayMarshalInfo fami = marshalInfo as FixedArrayMarshalInfo; if (fami != null) { output.Write("[{0}]", fami.Size); if (fami.ElementType != NativeType.None) { output.Write(' '); WriteNativeType(fami.ElementType); } } break; case NativeType.ByValStr: output.Write("byvalstr"); break; case NativeType.ANSIBStr: output.Write("ansi bstr"); break; case NativeType.TBStr: output.Write("tbstr"); break; case NativeType.VariantBool: output.Write("variant bool"); break; case NativeType.ASAny: output.Write("as any"); break; case NativeType.LPStruct: output.Write("lpstruct"); break; case NativeType.CustomMarshaler: CustomMarshalInfo cmi = marshalInfo as CustomMarshalInfo; if (cmi == null) { goto default; } output.Write("custom(\"{0}\", \"{1}\"", CSharp.OutputVisitor.ConvertString(cmi.ManagedType.FullName), CSharp.OutputVisitor.ConvertString(cmi.Cookie)); if (cmi.Guid != Guid.Empty || !string.IsNullOrEmpty(cmi.UnmanagedType)) { output.Write(", \"{0}\", \"{1}\"", cmi.Guid.ToString(), CSharp.OutputVisitor.ConvertString(cmi.UnmanagedType)); } output.Write(')'); break; case NativeType.Error: output.Write("error"); break; default: output.Write(nativeType.ToString()); break; } }
private void WriteMarshalInfo(MarshalInfo marshalInfo) { _output.Write("marshal("); WriteNativeType(marshalInfo.NativeType, marshalInfo); _output.Write(") "); }
public PrimitiveMarshalInfoWriter(TypeReference type, MarshalInfo marshalInfo, MarshalType marshalType) : base(type) { this._marshaledTypeName = DefaultMarshalInfoWriter.Naming.ForVariable(type); switch (type.MetadataType) { case MetadataType.Void: this._nativeSizeWithoutPointers = 1; this._nativeSize = "1"; break; case MetadataType.Boolean: if (marshalType == MarshalType.WindowsRuntime) { this._nativeSizeWithoutPointers = 1; this._nativeSize = "1"; this._marshaledTypeName = "bool"; break; } this._nativeSizeWithoutPointers = 4; this._nativeSize = "4"; this._marshaledTypeName = "int32_t"; break; case MetadataType.Char: if (marshalType == MarshalType.WindowsRuntime) { this._nativeSizeWithoutPointers = 2; this._nativeSize = "2"; this._marshaledTypeName = "Il2CppChar"; break; } this._nativeSizeWithoutPointers = 1; this._nativeSize = "1"; this._marshaledTypeName = "uint8_t"; break; case MetadataType.SByte: case MetadataType.Byte: this._nativeSizeWithoutPointers = 1; break; case MetadataType.Int16: case MetadataType.UInt16: this._nativeSizeWithoutPointers = 2; break; case MetadataType.Int32: case MetadataType.UInt32: case MetadataType.Single: this._nativeSizeWithoutPointers = 4; break; case MetadataType.Int64: case MetadataType.UInt64: case MetadataType.Double: this._nativeSizeWithoutPointers = 8; break; case MetadataType.Pointer: this._nativeSizeWithoutPointers = 0; break; case MetadataType.IntPtr: this._marshaledTypeName = DefaultMarshalInfoWriter.Naming.ForIntPtrT; this._nativeSizeWithoutPointers = 0; break; case MetadataType.UIntPtr: this._marshaledTypeName = DefaultMarshalInfoWriter.Naming.ForUIntPtrT; this._nativeSizeWithoutPointers = 0; break; } if (marshalInfo != null) { switch (marshalInfo.NativeType) { case NativeType.Boolean: case NativeType.I4: this._nativeSize = "4"; this._nativeSizeWithoutPointers = 4; this._marshaledTypeName = "int32_t"; break; case NativeType.I1: this._nativeSize = "1"; this._nativeSizeWithoutPointers = 1; this._marshaledTypeName = "int8_t"; break; case NativeType.U1: this._nativeSize = "1"; this._nativeSizeWithoutPointers = 1; this._marshaledTypeName = "uint8_t"; break; case NativeType.I2: this._nativeSize = "2"; this._nativeSizeWithoutPointers = 2; this._marshaledTypeName = "int16_t"; break; case NativeType.U2: this._nativeSize = "2"; this._nativeSizeWithoutPointers = 2; this._marshaledTypeName = "uint16_t"; break; case NativeType.U4: this._nativeSize = "4"; this._nativeSizeWithoutPointers = 4; this._marshaledTypeName = "uint32_t"; break; case NativeType.I8: this._nativeSize = "8"; this._nativeSizeWithoutPointers = 8; this._marshaledTypeName = "int64_t"; break; case NativeType.U8: this._nativeSize = "8"; this._nativeSizeWithoutPointers = 8; this._marshaledTypeName = "uint64_t"; break; case NativeType.R4: this._nativeSize = "4"; this._nativeSizeWithoutPointers = 4; this._marshaledTypeName = "float"; break; case NativeType.R8: this._nativeSize = "8"; this._nativeSizeWithoutPointers = 8; this._marshaledTypeName = "double"; break; case NativeType.Int: this._nativeSize = "sizeof(void*)"; this._nativeSizeWithoutPointers = 0; this._marshaledTypeName = DefaultMarshalInfoWriter.Naming.ForIntPtrT; break; case NativeType.UInt: this._nativeSize = "sizeof(void*)"; this._nativeSizeWithoutPointers = 0; this._marshaledTypeName = DefaultMarshalInfoWriter.Naming.ForUIntPtrT; break; case NativeType.VariantBool: this._nativeSize = "2"; this._nativeSizeWithoutPointers = 2; this._marshaledTypeName = "IL2CPP_VARIANT_BOOL"; break; } } this._marshaledTypes = new MarshaledType[] { new MarshaledType(this._marshaledTypeName, this._marshaledTypeName) }; if (this._nativeSize == null) { this._nativeSize = base.NativeSize; } }