|
|
@ -80,12 +80,23 @@ namespace CppSharp.Generators.CSharp |
|
|
|
supportBefore.WriteLine($"if ({Context.ReturnVarName} != null)"); |
|
|
|
supportBefore.WriteLine($"if ({Context.ReturnVarName} != null)"); |
|
|
|
supportBefore.WriteOpenBraceAndIndent(); |
|
|
|
supportBefore.WriteOpenBraceAndIndent(); |
|
|
|
supportBefore.WriteLine($"{value} = new {arrayType}[{array.Size}];"); |
|
|
|
supportBefore.WriteLine($"{value} = new {arrayType}[{array.Size}];"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (CheckIfArrayCanBeCopiedUsingMemoryCopy(array)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var arraySizeInBytes = array.GetSizeInBytes(); |
|
|
|
|
|
|
|
var fixedArray = Generator.GeneratedIdentifier($"{value}fixed"); |
|
|
|
|
|
|
|
supportBefore.WriteLine($"fixed (void* {fixedArray} = {value})"); |
|
|
|
|
|
|
|
supportBefore.WriteLineIndent( |
|
|
|
|
|
|
|
$"System.Buffer.MemoryCopy((void*){Context.ReturnVarName}, {fixedArray}, {arraySizeInBytes}, {arraySizeInBytes});"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
supportBefore.WriteLine($"for (int i = 0; i < {array.Size}; i++)"); |
|
|
|
supportBefore.WriteLine($"for (int i = 0; i < {array.Size}; i++)"); |
|
|
|
if (array.Type.IsPointerToPrimitiveType(PrimitiveType.Void)) |
|
|
|
if (array.Type.IsPointerToPrimitiveType(PrimitiveType.Void)) |
|
|
|
supportBefore.WriteLineIndent($@"{value}[i] = new global::System.IntPtr({
|
|
|
|
supportBefore.WriteLineIndent($@"{value}[i] = new global::System.IntPtr({
|
|
|
|
Context.ReturnVarName}[i]);");
|
|
|
|
Context.ReturnVarName}[i]);");
|
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
var finalArrayType = arrayType.GetPointee() ?? arrayType; |
|
|
|
var finalArrayType = arrayType.GetPointee() ?? arrayType; |
|
|
|
Class @class; |
|
|
|
Class @class; |
|
|
|
if ((finalArrayType.TryGetClass(out @class)) && @class.IsRefType) |
|
|
|
if ((finalArrayType.TryGetClass(out @class)) && @class.IsRefType) |
|
|
@ -114,6 +125,7 @@ namespace CppSharp.Generators.CSharp |
|
|
|
Context.ReturnVarName}[i];");
|
|
|
|
Context.ReturnVarName}[i];");
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
supportBefore.UnindentAndWriteCloseBrace(); |
|
|
|
supportBefore.UnindentAndWriteCloseBrace(); |
|
|
|
Context.Return.Write(value); |
|
|
|
Context.Return.Write(value); |
|
|
|
break; |
|
|
|
break; |
|
|
@ -428,6 +440,12 @@ namespace CppSharp.Generators.CSharp |
|
|
|
Context.Return.Write(intermediateArray); |
|
|
|
Context.Return.Write(intermediateArray); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool CheckIfArrayCanBeCopiedUsingMemoryCopy(ArrayType array) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return array.Type.IsPrimitiveType(out var primitive) && |
|
|
|
|
|
|
|
(!Context.Context.Options.MarshalCharAsManagedChar || primitive != PrimitiveType.Char); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private readonly CSharpTypePrinter typePrinter; |
|
|
|
private readonly CSharpTypePrinter typePrinter; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|