diff --git a/src/Generator/Generators/CLI/CLISourcesTemplate.cs b/src/Generator/Generators/CLI/CLISourcesTemplate.cs index d651edf2..c02a9b8e 100644 --- a/src/Generator/Generators/CLI/CLISourcesTemplate.cs +++ b/src/Generator/Generators/CLI/CLISourcesTemplate.cs @@ -901,8 +901,9 @@ namespace CppSharp.Generators.CLI var paramType = param.Type; if (paramType is PointerType) { + if (!paramType.IsReference()) + paramMarshal.Prefix = "&"; paramType = (paramType as PointerType).Pointee; - paramMarshal.Prefix = "&"; } var typePrinter = new CppTypePrinter(Driver.TypeDatabase); diff --git a/tests/Basic/Basic.Tests.cs b/tests/Basic/Basic.Tests.cs index 284a7480..846d4d99 100644 --- a/tests/Basic/Basic.Tests.cs +++ b/tests/Basic/Basic.Tests.cs @@ -54,6 +54,16 @@ public class BasicTests Assert.That(f, Is.EqualTo(10.0f)); } + [Test] + public void TestPrimitiveOutRefParameters() + { + var hello = new Hello(); + + float f; + Assert.That(hello.TestPrimitiveOutRef(out f), Is.True); + Assert.That(f, Is.EqualTo(10.0f)); + } + [Test] public void TestNullRef() { diff --git a/tests/Basic/Basic.cpp b/tests/Basic/Basic.cpp index 9bcb3dfb..3bf97fa4 100644 --- a/tests/Basic/Basic.cpp +++ b/tests/Basic/Basic.cpp @@ -101,6 +101,12 @@ bool Hello::TestPrimitiveOut(CS_OUT float* f) return true; } +bool Hello::TestPrimitiveOutRef(CS_OUT float& f) +{ + f = 10; + return true; +} + int unsafeFunction(const Bar& ret, char* testForString, void (*foo)(int)) { return ret.A; diff --git a/tests/Basic/Basic.cs b/tests/Basic/Basic.cs index f01f4b2d..4d4043d3 100644 --- a/tests/Basic/Basic.cs +++ b/tests/Basic/Basic.cs @@ -16,6 +16,7 @@ namespace CppSharp.Tests lib.SetClassAsValueType("Bar"); lib.SetClassAsValueType("Bar2"); lib.SetMethodParameterUsage("Hello", "TestPrimitiveOut", 1, ParameterUsage.Out); + lib.SetMethodParameterUsage("Hello", "TestPrimitiveOutRef", 1, ParameterUsage.Out); } static class Program diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index ead072dd..0dd190d2 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -88,7 +88,7 @@ public: Hello* RetNull(); bool TestPrimitiveOut(CS_OUT float* f); - + bool TestPrimitiveOutRef(CS_OUT float& f); }; class DLL_API AbstractFoo