diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index 66c6a4e9..3c140fb5 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -1169,7 +1169,9 @@ namespace CppSharp.Generators.CSharp var ctx = new CSharpMarshalContext(Context) { ArgName = decl.Name, - ReturnVarName = (isRefTypeArray ? string.Empty : "*") + Generator.GeneratedIdentifier("ptr"), + ReturnVarName = (isRefTypeArray || + (arrayType != null && arrayType.Type.Desugar().IsPrimitiveType()) ? string.Empty : "*") + + Generator.GeneratedIdentifier("ptr"), ReturnType = new QualifiedType(var.Type) }; diff --git a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs index 5cdd0981..002c395a 100644 --- a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs +++ b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs @@ -139,14 +139,15 @@ namespace CppSharp.Generators.CSharp Type arrayType = array.Type.Desugar(); PrimitiveType primitiveType; - if (arrayType.IsPointerToPrimitiveType(out primitiveType) && - !(arrayType is FunctionType)) + if ((arrayType.IsPointerToPrimitiveType(out primitiveType) && + !(arrayType is FunctionType)) || + (arrayType.IsPrimitiveType() && MarshalKind != CSharpMarshalKind.NativeField)) { if (primitiveType == PrimitiveType.Void) { - return "void**"; + return "void*"; } - return string.Format("{0}*", array.Type.Visit(this, quals)); + return string.Format("{0}", array.Type.Visit(this, quals)); } if (TypePrinterContext.Parameter != null) diff --git a/tests/CSharp/CSharp.Tests.cs b/tests/CSharp/CSharp.Tests.cs index a0f34e9d..da491b95 100644 --- a/tests/CSharp/CSharp.Tests.cs +++ b/tests/CSharp/CSharp.Tests.cs @@ -555,6 +555,13 @@ public unsafe class CSharpTests : GeneratorTestFixture } } + [Test] + public void TestConstantArray() + { + Assert.That(CSharp.CSharp.VariableWithFixedPrimitiveArray[0], Is.EqualTo(5)); + Assert.That(CSharp.CSharp.VariableWithFixedPrimitiveArray[1], Is.EqualTo(10)); + } + [Test] public void TestOverrideVirtualWithString() { diff --git a/tests/CSharp/CSharp.cpp b/tests/CSharp/CSharp.cpp index fc686a34..46dea891 100644 --- a/tests/CSharp/CSharp.cpp +++ b/tests/CSharp/CSharp.cpp @@ -1064,3 +1064,5 @@ bool HasVirtualTakesReturnsProblematicTypes::callsVirtualToReturnBool(bool b) { return virtualTakesAndReturnsBool(b); } + +extern const unsigned char variableWithFixedPrimitiveArray[2] = { 5, 10 }; diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index 4f30b830..b5ae92bb 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -980,3 +980,5 @@ public: virtual bool virtualTakesAndReturnsBool(bool b); bool callsVirtualToReturnBool(bool b); }; + +extern const unsigned char DLL_API variableWithFixedPrimitiveArray[2];