protected bool IsOutParameter(MarshaledParameter parameter) { TypeReference parameterType = parameter.ParameterType; if (parameter.IsOut && !parameterType.IsValueType()) { return(true); } if (parameter.IsIn && !parameter.IsOut) { return(false); } return(parameter.ParameterType.IsByReference || MarshalingUtils.IsStringBuilder(parameterType)); }
protected CustomMarshalInfoWriter(TypeDefinition type, MarshalType marshalType, bool forFieldMarshaling) : base(type) { this._type = type; this._marshalType = marshalType; string str = DefaultMarshalInfoWriter.Naming.ForTypeNameOnly(type); string str2 = '_' + MarshalingUtils.MarshalTypeToString(marshalType); this._forFieldMarshaling = forFieldMarshaling; this._marshaledTypeName = GetMarshaledTypeName(type, marshalType); this._marshaledDecoratedTypeName = !this.TreatAsValueType() ? (this._marshaledTypeName + "*") : this._marshaledTypeName; this._marshaledTypes = new MarshaledType[] { new MarshaledType(this._marshaledTypeName, this._marshaledDecoratedTypeName) }; this._marshalToNativeFunctionName = $"{str}_marshal{str2}"; this._marshalFromNativeFunctionName = $"{str}_marshal{str2}_back"; this._marshalCleanupFunctionName = $"{str}_marshal{str2}_cleanup"; this._marshalToNativeFunctionDeclaration = $"extern "C" void {this.MarshalToNativeFunctionName}(const {str}& unmarshaled, {this._marshaledTypeName}& marshaled)"; this._marshalFromNativeFunctionDeclaration = $"extern "C" void {this._marshalFromNativeFunctionName}(const {this._marshaledTypeName}& marshaled, {str}& unmarshaled)"; this._marshalCleanupFunctionDeclaration = $"extern "C" void {this.MarshalCleanupFunctionName}({this._marshaledTypeName}& marshaled)"; if (<>f__am$cache0 == null) {
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))); }
protected override void WriteMarshalToNativeMethodDefinition(CppCodeWriter writer) { string uniqueIdentifier = $"{DefaultMarshalInfoWriter.Naming.ForType(base._type)}_{MarshalingUtils.MarshalTypeToString(base._marshalType)}_ToNativeMethodDefinition"; MethodWriter.WriteMethodWithMetadataInitialization(writer, base._marshalToNativeFunctionDeclaration, base._marshalToNativeFunctionName, delegate(CppCodeWriter bodyWriter, MetadataUsage metadataUsage, MethodUsage methodUsage) { DefaultRuntimeMetadataAccess metadataAccess = new DefaultRuntimeMetadataAccess(null, metadataUsage, methodUsage); for (int j = 0; j < base.Fields.Length; j++) { base.FieldMarshalInfoWriters[j].WriteMarshalVariableToNative(bodyWriter, new ManagedMarshalValue("unmarshaled", base.Fields[j]), base.FieldMarshalInfoWriters[j].UndecorateVariable($"marshaled.{DefaultMarshalInfoWriter.Naming.ForField(base.Fields[j])}"), null, metadataAccess); } }, uniqueIdentifier); }
protected override void WriteMarshalFromNativeMethodDefinition(CppCodeWriter writer) { string uniqueIdentifier = $"{DefaultMarshalInfoWriter.Naming.ForType(base._type)}_{MarshalingUtils.MarshalTypeToString(base._marshalType)}_FromNativeMethodDefinition"; MethodWriter.WriteMethodWithMetadataInitialization(writer, base._marshalFromNativeFunctionDeclaration, base._marshalFromNativeFunctionName, delegate(CppCodeWriter bodyWriter, MetadataUsage metadataUsage, MethodUsage methodUsage) { DefaultRuntimeMetadataAccess metadataAccess = new DefaultRuntimeMetadataAccess(null, metadataUsage, methodUsage); for (int j = 0; j < base.Fields.Length; j++) { FieldDefinition field = base.Fields[j]; ManagedMarshalValue destinationVariable = new ManagedMarshalValue("unmarshaled", field); if (!field.FieldType.IsValueType()) { base.FieldMarshalInfoWriters[j].WriteMarshalVariableFromNative(bodyWriter, base.FieldMarshalInfoWriters[j].UndecorateVariable($"marshaled.{DefaultMarshalInfoWriter.Naming.ForField(field)}"), destinationVariable, null, false, false, metadataAccess); } else { string name = destinationVariable.GetNiceName() + "_temp_" + j; bodyWriter.WriteVariable(field.FieldType, name); base.FieldMarshalInfoWriters[j].WriteMarshalVariableFromNative(bodyWriter, $"marshaled.{DefaultMarshalInfoWriter.Naming.ForField(field)}", new ManagedMarshalValue(name), null, false, false, metadataAccess); bodyWriter.WriteLine(destinationVariable.Store(name)); } } }, uniqueIdentifier); }
public static ReversePInvokeMethodBodyWriter Create(MethodReference managedMethod) { MethodReference interopMethod = GetInteropMethod(managedMethod); return(new ReversePInvokeMethodBodyWriter(managedMethod, interopMethod, MarshalingUtils.UseUnicodeAsDefaultMarshalingForStringParameters(interopMethod))); }
public PInvokeMethodBodyWriter(MethodReference interopMethod) : base(interopMethod, interopMethod, MarshalType.PInvoke, MarshalingUtils.UseUnicodeAsDefaultMarshalingForStringParameters(interopMethod)) { this._methodDefinition = interopMethod.Resolve(); this._pinvokeInfo = this._methodDefinition.PInvokeInfo; }