diff --git a/src/Generator/Generators/CLI/CLISourcesTemplate.cs b/src/Generator/Generators/CLI/CLISourcesTemplate.cs index 3feaf045..a3e233a7 100644 --- a/src/Generator/Generators/CLI/CLISourcesTemplate.cs +++ b/src/Generator/Generators/CLI/CLISourcesTemplate.cs @@ -1067,7 +1067,10 @@ namespace CppSharp.Generators.CLI var typePrinter = new CppTypePrinter(Driver.TypeDatabase); var type = paramType.Visit(typePrinter); - WriteLine("{0} {1};", type, argName); + if (param.IsInOut) + WriteLine("{0} {1} = {2};", type, argName, param.Name); + else + WriteLine("{0} {1};", type, argName); } else { diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index da536cd2..6866c8bd 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -474,9 +474,12 @@ namespace CppSharp.Generators.CSharp { var typeName = Type.TypePrinterDelegate(pointee); - Context.SupportBefore.WriteLine("{0} _{1};", typeName, param.Name); - Context.Return.Write("&_{0}", param.Name); + if (param.IsInOut) + Context.SupportBefore.WriteLine("{0} _{1} = {1};", typeName, param.Name); + else + Context.SupportBefore.WriteLine("{0} _{1};", typeName, param.Name); + Context.Return.Write("&_{0}", param.Name); } else Context.Return.Write(Helpers.SafeIdentifier(Context.Parameter.Name)); diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 3d003ecb..062745db 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -2503,7 +2503,7 @@ namespace CppSharp.Generators.CSharp case ParameterUsage.Out: return "out "; case ParameterUsage.InOut: - return "ref"; + return "ref "; default: return string.Empty; } diff --git a/tests/Basic/Basic.Tests.cs b/tests/Basic/Basic.Tests.cs index dcf25e84..aa3df3b7 100644 --- a/tests/Basic/Basic.Tests.cs +++ b/tests/Basic/Basic.Tests.cs @@ -77,6 +77,26 @@ public class BasicTests : GeneratorTestFixture Assert.That(f, Is.EqualTo(10.0f)); } + [Test] + public void TestPrimitiveInOutParameters() + { + var hello = new Hello(); + + int i = 10; + Assert.That(hello.TestPrimitiveInOut(ref i), Is.True); + Assert.That(i, Is.EqualTo(20)); + } + + [Test] + public void TestPrimitiveInOutRefParameters() + { + var hello = new Hello(); + + int i = 10; + Assert.That(hello.TestPrimitiveInOutRef(ref i), Is.True); + Assert.That(i, Is.EqualTo(20)); + } + [Test] public void TestNullRef() { diff --git a/tests/Basic/Basic.cpp b/tests/Basic/Basic.cpp index 48547de4..90e9d7d3 100644 --- a/tests/Basic/Basic.cpp +++ b/tests/Basic/Basic.cpp @@ -169,6 +169,18 @@ bool Hello::TestPrimitiveOutRef(CS_OUT float& f) return true; } +bool Hello::TestPrimitiveInOut(CS_IN_OUT int* i) +{ + *i += 10; + return true; +} + +bool Hello::TestPrimitiveInOutRef(CS_IN_OUT int& i) +{ + i += 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 fbf14581..f5dd6e32 100644 --- a/tests/Basic/Basic.cs +++ b/tests/Basic/Basic.cs @@ -31,6 +31,8 @@ namespace CppSharp.Tests ctx.SetClassAsValueType("Bar2"); ctx.SetMethodParameterUsage("Hello", "TestPrimitiveOut", 1, ParameterUsage.Out); ctx.SetMethodParameterUsage("Hello", "TestPrimitiveOutRef", 1, ParameterUsage.Out); + ctx.SetMethodParameterUsage("Hello", "TestPrimitiveInOut", 1, ParameterUsage.InOut); + ctx.SetMethodParameterUsage("Hello", "TestPrimitiveInOutRef", 1, ParameterUsage.InOut); } public static void Main(string[] args) diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index cebe6778..de936323 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -123,6 +123,9 @@ public: bool TestPrimitiveOut(CS_OUT float* f); bool TestPrimitiveOutRef(CS_OUT float& f); + + bool TestPrimitiveInOut(CS_IN_OUT int* i); + bool TestPrimitiveInOutRef(CS_IN_OUT int& i); }; class DLL_API AbstractFoo diff --git a/tests/Tests.h b/tests/Tests.h index 1b493c67..1c2cbaf2 100644 --- a/tests/Tests.h +++ b/tests/Tests.h @@ -22,4 +22,5 @@ #endif #endif -#define CS_OUT \ No newline at end of file +#define CS_OUT +#define CS_IN_OUT \ No newline at end of file