/// <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 static MarshalInfo GetMarshalInfo(this IMarshalInfoProvider self, ref MarshalInfo variable, ModuleDefinition module) { if (!module.HasImage()) { return(null); } return(module.Read <IMarshalInfoProvider, MarshalInfo>(ref variable, self, (provider, reader) => reader.ReadMarshalInfo(provider))); }
public MarshaledParameter(string name, string nameInGeneratedCode, TypeReference parameterType, Mono.Cecil.MarshalInfo marshalInfo, bool isIn, bool isOut) { this.Name = name; this.NameInGeneratedCode = nameInGeneratedCode; this.ParameterType = parameterType; this.MarshalInfo = marshalInfo; this.IsIn = isIn; this.IsOut = isOut; }
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(string.Format("BlittableByReferenceMarshalInfoWriter cannot marshal {0}&.", 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; }
public ComSafeArrayMarshalInfoWriter(ArrayType type, MarshalInfo marshalInfo) : base(type) { this._elementType = type.ElementType; this._marshalInfo = marshalInfo as SafeArrayMarshalInfo; if (this._marshalInfo == null) { throw new InvalidOperationException(string.Format("SafeArray type '{0}' has invalid MarshalAsAttribute.", type.FullName)); } if ((this._marshalInfo.ElementType == VariantType.BStr) && (this._elementType.MetadataType != MetadataType.String)) { throw new InvalidOperationException(string.Format("SafeArray(BSTR) type '{0}' has invalid MarshalAsAttribute.", type.FullName)); } NativeType nativeElementType = this.GetNativeElementType(); this._elementTypeMarshalInfoWriter = MarshalDataCollector.MarshalInfoWriterFor(this._elementType, MarshalType.COM, new MarshalInfo(nativeElementType), false, false, false, null); string name = string.Format("Il2CppSafeArray/*{0}*/*", this._marshalInfo.ElementType.ToString().ToUpper()); this._marshaledTypes = new MarshaledType[] { new MarshaledType(name, name) }; }
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) && !Extensions.IsInterface(definition)) && !Extensions.IsSystemObject(type); this._defaultInterface = !this._isClass ? type : Extensions.ExtractDefaultInterface(definition); this._managedTypeName = !this._isClass ? DefaultMarshalInfoWriter.Naming.ForTypeNameOnly(DefaultMarshalInfoWriter.TypeProvider.SystemObject) : DefaultMarshalInfoWriter.Naming.ForTypeNameOnly(type); if (Extensions.IsSystemObject(type)) { 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 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))); }
private ProjectReference GetMarshalInfoReference( MarshalInfo marshalInfo, AuditEntryParameters parameters) { var customMarshalInfo = marshalInfo as CustomMarshalInfo; if (customMarshalInfo != null && customMarshalInfo.ManagedType != null) { var typeDefinition = customMarshalInfo.ManagedType.Resolve(); if (typeDefinition != null) { parameters.AddToCheckedTypes(typeDefinition); return parameters.FindProjectReference(typeDefinition); } } return null; }
public void WriteMarshalInfo(MarshalInfo marshal_info) { this.WriteNativeType(marshal_info.native); NativeType native = marshal_info.native; if (native == NativeType.FixedSysString) { FixedSysStringMarshalInfo info4 = (FixedSysStringMarshalInfo)marshal_info; if (info4.size > -1) { base.WriteCompressedUInt32((uint)info4.size); } } else { switch (native) { case NativeType.SafeArray: { SafeArrayMarshalInfo info2 = (SafeArrayMarshalInfo)marshal_info; if (info2.element_type != VariantType.None) { this.WriteVariantType(info2.element_type); } return; } case NativeType.FixedArray: { FixedArrayMarshalInfo info3 = (FixedArrayMarshalInfo)marshal_info; if (info3.size > -1) { base.WriteCompressedUInt32((uint)info3.size); } if (info3.element_type != NativeType.None) { this.WriteNativeType(info3.element_type); } return; } } switch (native) { case NativeType.Array: { ArrayMarshalInfo info = (ArrayMarshalInfo)marshal_info; if (info.element_type != NativeType.None) { this.WriteNativeType(info.element_type); } if (info.size_parameter_index > -1) { base.WriteCompressedUInt32((uint)info.size_parameter_index); } if (info.size > -1) { base.WriteCompressedUInt32((uint)info.size); } if (info.size_parameter_multiplier > -1) { base.WriteCompressedUInt32((uint)info.size_parameter_multiplier); } return; } case NativeType.LPStruct: break; case NativeType.CustomMarshaler: { CustomMarshalInfo info5 = (CustomMarshalInfo)marshal_info; this.WriteUTF8String((info5.guid != Guid.Empty) ? info5.guid.ToString() : string.Empty); this.WriteUTF8String(info5.unmanaged_type); this.WriteTypeReference(info5.managed_type); this.WriteUTF8String(info5.cookie); break; } default: return; } } }
/// <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; }
private void WriteMarshalInfo(MarshalInfo marshalInfo) { WriteKeyword("marshal"); WriteToken("("); WriteNativeType(marshalInfo.NativeType, marshalInfo); WriteToken("("); WriteSpace(); }
private void WriteNativeType(NativeType nativeType, MarshalInfo marshalInfo = null) { switch (nativeType) { case NativeType.None: break; case NativeType.Boolean: WriteKeyword("bool"); break; case NativeType.I1: WriteKeyword("int8"); break; case NativeType.U1: WriteKeyword("unsigned int8"); break; case NativeType.I2: WriteKeyword("int16"); break; case NativeType.U2: WriteKeyword("unsigned int16"); break; case NativeType.I4: WriteKeyword("int32"); break; case NativeType.U4: WriteKeyword("unsigned int32"); break; case NativeType.I8: WriteKeyword("int64"); break; case NativeType.U8: WriteKeyword("unsigned int64"); break; case NativeType.R4: WriteKeyword("float32"); break; case NativeType.R8: WriteKeyword("float64"); break; case NativeType.LPStr: WriteKeyword("lpstr"); break; case NativeType.Int: WriteKeyword("int"); break; case NativeType.UInt: WriteKeyword("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); WriteToken("["); if (ami.SizeParameterMultiplier == 0) { WriteLiteral(ami.Size.ToString()); } else { if (ami.Size >= 0) WriteLiteral(ami.Size.ToString()); WriteSpace(); WriteToken("+"); WriteSpace(); WriteLiteral(ami.SizeParameterIndex.ToString()); } WriteToken("]"); break; case NativeType.Currency: WriteKeyword("currency"); break; case NativeType.BStr: WriteKeyword("bstr"); break; case NativeType.LPWStr: WriteKeyword("lpwstr"); break; case NativeType.LPTStr: WriteKeyword("lptstr"); break; case NativeType.FixedSysString: WriteKeyword(string.Format("fixed sysstring[{0}]", ((FixedSysStringMarshalInfo)marshalInfo).Size)); break; case NativeType.IUnknown: WriteKeyword("iunknown"); break; case NativeType.IDispatch: WriteKeyword("idispatch"); break; case NativeType.Struct: WriteKeyword("struct"); break; case NativeType.IntF: WriteKeyword("interface"); break; case NativeType.SafeArray: WriteKeyWordPostSpace("safearray"); SafeArrayMarshalInfo sami = marshalInfo as SafeArrayMarshalInfo; if (sami != null) { switch (sami.ElementType) { case VariantType.None: break; case VariantType.I2: WriteKeyword("int16"); break; case VariantType.I4: WriteKeyword("int32"); break; case VariantType.R4: WriteKeyword("float32"); break; case VariantType.R8: WriteKeyword("float64"); break; case VariantType.CY: WriteKeyword("currency"); break; case VariantType.Date: WriteKeyword("date"); break; case VariantType.BStr: WriteKeyword("bstr"); break; case VariantType.Dispatch: WriteKeyword("idispatch"); break; case VariantType.Error: WriteKeyword("error"); break; case VariantType.Bool: WriteKeyword("bool"); break; case VariantType.Variant: WriteKeyword("variant"); break; case VariantType.Unknown: WriteKeyword("iunknown"); break; case VariantType.Decimal: WriteKeyword("decimal"); break; case VariantType.I1: WriteKeyword("int8"); break; case VariantType.UI1: WriteKeyword("unsigned int8"); break; case VariantType.UI2: WriteKeyword("unsigned int16"); break; case VariantType.UI4: WriteKeyword("unsigned int32"); break; case VariantType.Int: WriteKeyword("int"); break; case VariantType.UInt: WriteKeyword("unsigned int"); break; default: WriteKeyword(sami.ElementType.ToString()); break; } } break; case NativeType.FixedArray: WriteKeyword("fixed array"); FixedArrayMarshalInfo fami = marshalInfo as FixedArrayMarshalInfo; if (fami != null) { WriteToken("["); WriteLiteral(fami.Size.ToString()); WriteToken("]"); if (fami.ElementType != NativeType.None) { WriteSpace(); WriteNativeType(fami.ElementType); } } break; case NativeType.ByValStr: WriteKeyword("byvalstr"); break; case NativeType.ANSIBStr: WriteKeyword("ansi bstr"); break; case NativeType.TBStr: WriteKeyword("tbstr"); break; case NativeType.VariantBool: WriteKeyword("variant bool"); break; case NativeType.ASAny: WriteKeyword("as any"); break; case NativeType.LPStruct: WriteKeyword("lpstruct"); break; case NativeType.CustomMarshaler: CustomMarshalInfo cmi = marshalInfo as CustomMarshalInfo; if (cmi == null) goto default; WriteKeyword("custom"); WriteToken("("); WriteLiteralInQuotes(ConvertString(cmi.ManagedType.FullName)); WriteTokenPostSpace(","); WriteLiteralInQuotes(ConvertString(cmi.Cookie)); if (cmi.Guid != Guid.Empty || !string.IsNullOrEmpty(cmi.UnmanagedType)) { WriteTokenPostSpace(","); WriteLiteralInQuotes(cmi.Guid.ToString()); WriteTokenPostSpace(","); WriteLiteralInQuotes(ConvertString(cmi.UnmanagedType)); } WriteToken(")"); break; case NativeType.Error: WriteKeyword("error"); break; default: WriteKeyword(nativeType.ToString()); break; } }
private void ProcessMarshallInfo(MarshalInfo marshalInfo) { var customMarshalInfo = marshalInfo as CustomMarshalInfo; if (customMarshalInfo != null) { AddType(customMarshalInfo.ManagedType); } }
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) {
string StringifyMarshalInfo (MarshalInfo mi) { var sb = new StringBuilder (); sb.Append ("marshal ("); string s = null; switch (mi.NativeType) { case NativeType.Array: { var ami = (mi as ArrayMarshalInfo); if (native_type_to_str.TryGetValue (ami.ElementType, out s)) { sb.Append (s); } sb.Append ("["); //Console.WriteLine ("// XXX: " + ami.Size + " " + ami.SizeParameterIndex + " " + ami.SizeParameterMultiplier); /* * Comments in metadata.c: * So if (param_num == 0) && (num_elem > 0), then * elem_mult == 0 -> the array size is num_elem * elem_mult == 1 -> the array size is @param_num + num_elem */ if (ami.Size != -1 && ami.Size != 0) sb.Append (ami.Size.ToString ()); if (ami.SizeParameterMultiplier != 0 && ami.SizeParameterIndex != -1) sb.Append ("+" + ami.SizeParameterIndex.ToString ()); sb.Append ("]"); break; } case NativeType.FixedArray: { var ami = (mi as FixedArrayMarshalInfo); /* if (native_type_to_str.TryGetValue (ami.ElementType, out s)) { sb.Append (s); } */ sb.Append ("fixed array [" + ami.Size + "]"); break; } case NativeType.FixedSysString: { var ami = (mi as FixedSysStringMarshalInfo); sb.Append ("fixed sysstring [" + ami.Size + "]"); break; } case NativeType.SafeArray: { var sami = (mi as SafeArrayMarshalInfo); sb.Append ("safearray "); switch (sami.ElementType) { case VariantType.Variant: sb.Append ("variant"); break; default: throw new NotImplementedException (); } break; } case NativeType.CustomMarshaler: { var cmi = (mi as CustomMarshalInfo); if (cmi.Guid != Guid.Empty || cmi.UnmanagedType != String.Empty) throw new NotImplementedException (); sb.Append ("custom (\"" + StringifyTypeNameReflection (cmi.ManagedType) + "\", \"" + EscapeString (cmi.Cookie) + "\")"); break; } default: if (native_type_to_str.TryGetValue (mi.NativeType, out s)) sb.Append (s); else throw new NotImplementedException (mi.NativeType.ToString ()); break; } sb.Append (")"); return sb.ToString (); }
static IAttribute ConvertMarshalInfo(MarshalInfo marshalInfo) { DefaultAttribute attr = new DefaultAttribute(marshalAsAttributeTypeRef, new[] { unmanagedTypeTypeRef }); attr.PositionalArguments.Add(new SimpleConstantValue(unmanagedTypeTypeRef, (int)marshalInfo.NativeType)); // TODO: handle classes derived from MarshalInfo return attr; }
public virtual void VisitMarshalSpec(MarshalInfo MarshalInfo) { }
public void WriteMarshalInfo(MarshalInfo marshal_info) { this.WriteNativeType(marshal_info.native); NativeType marshalInfo = marshal_info.native; if (marshalInfo <= NativeType.SafeArray) { if (marshalInfo == NativeType.FixedSysString) { FixedSysStringMarshalInfo fixedSysStringMarshalInfo = (FixedSysStringMarshalInfo)marshal_info; if (fixedSysStringMarshalInfo.size > -1) { base.WriteCompressedUInt32((uint)fixedSysStringMarshalInfo.size); } return; } if (marshalInfo != NativeType.SafeArray) { return; } SafeArrayMarshalInfo safeArrayMarshalInfo = (SafeArrayMarshalInfo)marshal_info; if (safeArrayMarshalInfo.element_type != VariantType.None) { this.WriteVariantType(safeArrayMarshalInfo.element_type); } return; } if (marshalInfo == NativeType.FixedArray) { FixedArrayMarshalInfo fixedArrayMarshalInfo = (FixedArrayMarshalInfo)marshal_info; if (fixedArrayMarshalInfo.size > -1) { base.WriteCompressedUInt32((uint)fixedArrayMarshalInfo.size); } if (fixedArrayMarshalInfo.element_type != NativeType.None) { this.WriteNativeType(fixedArrayMarshalInfo.element_type); } return; } if (marshalInfo != NativeType.Array) { if (marshalInfo != NativeType.CustomMarshaler) { return; } CustomMarshalInfo customMarshalInfo = (CustomMarshalInfo)marshal_info; this.WriteUTF8String((customMarshalInfo.guid != Guid.Empty ? customMarshalInfo.guid.ToString() : string.Empty)); this.WriteUTF8String(customMarshalInfo.unmanaged_type); this.WriteTypeReference(customMarshalInfo.managed_type); this.WriteUTF8String(customMarshalInfo.cookie); return; } ArrayMarshalInfo arrayMarshalInfo = (ArrayMarshalInfo)marshal_info; if (arrayMarshalInfo.element_type != NativeType.None) { this.WriteNativeType(arrayMarshalInfo.element_type); } if (arrayMarshalInfo.size_parameter_index > -1) { base.WriteCompressedUInt32((uint)arrayMarshalInfo.size_parameter_index); } if (arrayMarshalInfo.size > -1) { base.WriteCompressedUInt32((uint)arrayMarshalInfo.size); } if (arrayMarshalInfo.size_parameter_multiplier > -1) { base.WriteCompressedUInt32((uint)arrayMarshalInfo.size_parameter_multiplier); } }
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); }
public StringMarshaller(MarshalInfo marshalInfo) { nativeType = marshalInfo != null ? marshalInfo.NativeType : NativeType.LPTStr; }
private MarshalInfo CopyMarshalInfo(MarshalInfo info) { return info == null ? null : new MarshalInfo(info.NativeType); }
public void WriteMarshalInfo(MarshalInfo marshal_info) { WriteNativeType(marshal_info.native); switch (marshal_info.native) { case NativeType.Array: { ArrayMarshalInfo arrayMarshalInfo = (ArrayMarshalInfo)marshal_info; if (arrayMarshalInfo.element_type != NativeType.None) { WriteNativeType(arrayMarshalInfo.element_type); } if (arrayMarshalInfo.size_parameter_index > -1) { base.WriteCompressedUInt32((uint)arrayMarshalInfo.size_parameter_index); } if (arrayMarshalInfo.size > -1) { base.WriteCompressedUInt32((uint)arrayMarshalInfo.size); } if (arrayMarshalInfo.size_parameter_multiplier > -1) { base.WriteCompressedUInt32((uint)arrayMarshalInfo.size_parameter_multiplier); } break; } case NativeType.SafeArray: { SafeArrayMarshalInfo safeArrayMarshalInfo = (SafeArrayMarshalInfo)marshal_info; if (safeArrayMarshalInfo.element_type != 0) { WriteVariantType(safeArrayMarshalInfo.element_type); } break; } case NativeType.FixedArray: { FixedArrayMarshalInfo fixedArrayMarshalInfo = (FixedArrayMarshalInfo)marshal_info; if (fixedArrayMarshalInfo.size > -1) { base.WriteCompressedUInt32((uint)fixedArrayMarshalInfo.size); } if (fixedArrayMarshalInfo.element_type != NativeType.None) { WriteNativeType(fixedArrayMarshalInfo.element_type); } break; } case NativeType.FixedSysString: { FixedSysStringMarshalInfo fixedSysStringMarshalInfo = (FixedSysStringMarshalInfo)marshal_info; if (fixedSysStringMarshalInfo.size > -1) { base.WriteCompressedUInt32((uint)fixedSysStringMarshalInfo.size); } break; } case NativeType.CustomMarshaler: { CustomMarshalInfo customMarshalInfo = (CustomMarshalInfo)marshal_info; WriteUTF8String((customMarshalInfo.guid != Guid.Empty) ? customMarshalInfo.guid.ToString() : string.Empty); WriteUTF8String(customMarshalInfo.unmanaged_type); WriteTypeReference(customMarshalInfo.managed_type); WriteUTF8String(customMarshalInfo.cookie); break; } } }