|
|
@ -166,10 +166,10 @@ namespace CppSharp.Types.Std.CSharp |
|
|
|
switch (encodingName) |
|
|
|
switch (encodingName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case nameof(Encoding.Unicode): |
|
|
|
case nameof(Encoding.Unicode): |
|
|
|
ctx.Before.WriteLine($@"var {bytePtr} = Marshal.StringToHGlobalUni({param});"); |
|
|
|
ctx.Before.WriteLine($"var {bytePtr} = Marshal.StringToHGlobalUni({param});"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case nameof(Encoding.Default): |
|
|
|
case nameof(Encoding.Default): |
|
|
|
ctx.Before.WriteLine($@"var {bytePtr} = Marshal.StringToHGlobalAnsi({param});"); |
|
|
|
ctx.Before.WriteLine($"var {bytePtr} = Marshal.StringToHGlobalAnsi({param});"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
{ |
|
|
|
{ |
|
|
@ -183,8 +183,8 @@ namespace CppSharp.Types.Std.CSharp |
|
|
|
$"Encoding bytes per char: {encodingBytesPerChar} is not implemented.") |
|
|
|
$"Encoding bytes per char: {encodingBytesPerChar} is not implemented.") |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
ctx.Before.WriteLine($@"var {bytes} = global::System.Text.Encoding.{encodingName}.GetBytes({param});"); |
|
|
|
ctx.Before.WriteLine($"var {bytes} = global::System.Text.Encoding.{encodingName}.GetBytes({param});"); |
|
|
|
ctx.Before.WriteLine($@"var {bytePtr} = Marshal.AllocHGlobal({bytes}.Length + {encodingBytesPerChar});"); |
|
|
|
ctx.Before.WriteLine($"var {bytePtr} = Marshal.AllocHGlobal({bytes}.Length + {encodingBytesPerChar});"); |
|
|
|
ctx.Before.WriteLine($"Marshal.Copy({bytes}, 0, {bytePtr}, {bytes}.Length);"); |
|
|
|
ctx.Before.WriteLine($"Marshal.Copy({bytes}, 0, {bytePtr}, {bytes}.Length);"); |
|
|
|
ctx.Before.WriteLine($"Marshal.{writeNulMethod}({bytePtr} + {bytes}.Length, 0);"); |
|
|
|
ctx.Before.WriteLine($"Marshal.{writeNulMethod}({bytePtr} + {bytes}.Length, 0);"); |
|
|
|
} |
|
|
|
} |
|
|
@ -196,8 +196,7 @@ namespace CppSharp.Types.Std.CSharp |
|
|
|
|
|
|
|
|
|
|
|
public override void MarshalToManaged(MarshalContext ctx) |
|
|
|
public override void MarshalToManaged(MarshalContext ctx) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (ctx.Parameter != null && !ctx.Parameter.IsOut && |
|
|
|
if (ctx.Parameter is { IsOut: false, IsInOut: false }) |
|
|
|
!ctx.Parameter.IsInOut) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
ctx.Return.Write(ctx.Parameter.Name); |
|
|
|
ctx.Return.Write(ctx.Parameter.Name); |
|
|
|
return; |
|
|
|
return; |
|
|
@ -215,7 +214,7 @@ namespace CppSharp.Types.Std.CSharp |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var encoding = $"global::System.Text.Encoding.{GetEncoding().Name}"; |
|
|
|
var encoding = $"global::System.Text.Encoding.{GetEncoding().Name}"; |
|
|
|
ctx.Return.Write($@"CppSharp.Runtime.MarshalUtil.GetString({encoding}, {returnVarName})"); |
|
|
|
ctx.Return.Write($"CppSharp.Runtime.MarshalUtil.GetString({encoding}, {returnVarName})"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private (Encoding Encoding, string Name) GetEncoding() |
|
|
|
private (Encoding Encoding, string Name) GetEncoding() |
|
|
@ -340,7 +339,7 @@ namespace CppSharp.Types.Std.CSharp |
|
|
|
{ |
|
|
|
{ |
|
|
|
var = $"&{ctx.ReturnVarName}"; |
|
|
|
var = $"&{ctx.ReturnVarName}"; |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Return.Write($@"{qualifiedBasicString}Extensions.{Helpers.InternalStruct}.{assign.Name}(new {typePrinter.IntPtrType}({var}), "); |
|
|
|
ctx.Return.Write($"{qualifiedBasicString}Extensions.{Helpers.InternalStruct}.{assign.Name}(new {typePrinter.IntPtrType}({var}), "); |
|
|
|
if (ctx.Parameter.Type.IsTemplateParameterType()) |
|
|
|
if (ctx.Parameter.Type.IsTemplateParameterType()) |
|
|
|
ctx.Return.Write("(string) (object) "); |
|
|
|
ctx.Return.Write("(string) (object) "); |
|
|
|
ctx.Return.Write($"{ctx.Parameter.Name})"); |
|
|
|
ctx.Return.Write($"{ctx.Parameter.Name})"); |
|
|
@ -349,15 +348,15 @@ namespace CppSharp.Types.Std.CSharp |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
var varBasicString = $"__basicString{ctx.ParameterIndex}"; |
|
|
|
var varBasicString = $"__basicString{ctx.ParameterIndex}"; |
|
|
|
ctx.Before.WriteLine($@"var {varBasicString} = new {basicString.Visit(typePrinter)}();"); |
|
|
|
ctx.Before.WriteLine($"var {varBasicString} = new {basicString.Visit(typePrinter)}();"); |
|
|
|
|
|
|
|
|
|
|
|
ctx.Before.Write($@"{qualifiedBasicString}Extensions.{assign.Name}({varBasicString}, "); |
|
|
|
ctx.Before.Write($"{qualifiedBasicString}Extensions.{assign.Name}({varBasicString}, "); |
|
|
|
if (ctx.Parameter.Type.IsTemplateParameterType()) |
|
|
|
if (ctx.Parameter.Type.IsTemplateParameterType()) |
|
|
|
ctx.Before.Write("(string) (object) "); |
|
|
|
ctx.Before.Write("(string) (object) "); |
|
|
|
ctx.Before.WriteLine($"{ctx.Parameter.Name});"); |
|
|
|
ctx.Before.WriteLine($"{ctx.Parameter.Name});"); |
|
|
|
|
|
|
|
|
|
|
|
ctx.Return.Write($"{varBasicString}.{Helpers.InstanceIdentifier}"); |
|
|
|
ctx.Return.Write($"{varBasicString}.{Helpers.InstanceIdentifier}"); |
|
|
|
ctx.Cleanup.WriteLine($@"{varBasicString}.Dispose({(!Type.IsAddress() || ctx.Parameter?.IsIndirect == true ? "disposing: true, callNativeDtor:false" : string.Empty)});"); |
|
|
|
ctx.Cleanup.WriteLine($"{varBasicString}.Dispose({(!Type.IsAddress() || ctx.Parameter?.IsIndirect == true ? "disposing: true, callNativeDtor:false" : string.Empty)});"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -371,7 +370,7 @@ namespace CppSharp.Types.Std.CSharp |
|
|
|
string varBasicString = $"__basicStringRet{ctx.ParameterIndex}"; |
|
|
|
string varBasicString = $"__basicStringRet{ctx.ParameterIndex}"; |
|
|
|
bool usePointer = type.IsAddress() || ctx.MarshalKind == MarshalKind.NativeField || |
|
|
|
bool usePointer = type.IsAddress() || ctx.MarshalKind == MarshalKind.NativeField || |
|
|
|
ctx.MarshalKind == MarshalKind.ReturnVariableArray; |
|
|
|
ctx.MarshalKind == MarshalKind.ReturnVariableArray; |
|
|
|
ctx.Before.WriteLine($@"var {varBasicString} = {basicString.Visit(typePrinter)}.{Helpers.CreateInstanceIdentifier}({(usePointer ? string.Empty : $"new {typePrinter.IntPtrType}(&")}{ctx.ReturnVarName}{(usePointer ? string.Empty : ")")});"); |
|
|
|
ctx.Before.WriteLine($"var {varBasicString} = {basicString.Visit(typePrinter)}.{Helpers.CreateInstanceIdentifier}({(usePointer ? string.Empty : $"new {typePrinter.IntPtrType}(&")}{ctx.ReturnVarName}{(usePointer ? string.Empty : ")")});"); |
|
|
|
string @string = $"{qualifiedBasicString}Extensions.{data.Name}({varBasicString})"; |
|
|
|
string @string = $"{qualifiedBasicString}Extensions.{data.Name}({varBasicString})"; |
|
|
|
if (usePointer) |
|
|
|
if (usePointer) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -392,7 +391,7 @@ namespace CppSharp.Types.Std.CSharp |
|
|
|
var names = new Stack<string>(); |
|
|
|
var names = new Stack<string>(); |
|
|
|
while (!(declContext is TranslationUnit)) |
|
|
|
while (!(declContext is TranslationUnit)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var isInlineNamespace = declContext is Namespace && ((Namespace)declContext).IsInline; |
|
|
|
var isInlineNamespace = declContext is Namespace { IsInline: true }; |
|
|
|
if (!isInlineNamespace) |
|
|
|
if (!isInlineNamespace) |
|
|
|
names.Push(declContext.Name); |
|
|
|
names.Push(declContext.Name); |
|
|
|
declContext = declContext.Namespace; |
|
|
|
declContext = declContext.Namespace; |
|
|
|