From 6ed05c2b5d7139e11b1d70814ee58b22d2968ddb Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 13 Sep 2016 23:49:15 +0300 Subject: [PATCH] Fixed the generated C# with properties constructed from a returned value and a taken reference. Signed-off-by: Dimitar Dobrev --- .../Generators/CSharp/CSharpSources.cs | 3 +++ tests/CSharp/CSharp.Tests.cs | 14 +++++++++++++ tests/CSharp/CSharp.cpp | 20 +++++++++++++++++++ tests/CSharp/CSharp.h | 11 +++++++++- 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index 12a08f35..54d32544 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -901,6 +901,9 @@ namespace CppSharp.Generators.CSharp param.QualifiedType = function.Parameters[0].QualifiedType; + if (!property.Type.Equals(param.Type) && property.Type.IsEnumType()) + param.Name = ctx.ArgName = "&" + param.Name; + var method = function as Method; if (function.SynthKind == FunctionSynthKind.AbstractImplCall) GenerateVirtualPropertyCall(method, @class.BaseClass, property, diff --git a/tests/CSharp/CSharp.Tests.cs b/tests/CSharp/CSharp.Tests.cs index a09fe503..c9da11b4 100644 --- a/tests/CSharp/CSharp.Tests.cs +++ b/tests/CSharp/CSharp.Tests.cs @@ -595,6 +595,20 @@ public unsafe class CSharpTests : GeneratorTestFixture } } + [Test] + public void TestEnumProperty() + { + using (var proprietor = new Proprietor()) + { + Assert.That(proprietor.Items, Is.EqualTo(Bar.Items.Item1)); + proprietor.Items = Bar.Items.Item2; + Assert.That(proprietor.Items, Is.EqualTo(Bar.Items.Item2)); + Assert.That(proprietor.ItemsByValue, Is.EqualTo(Bar.Items.Item1)); + proprietor.ItemsByValue = Bar.Items.Item2; + Assert.That(proprietor.ItemsByValue, Is.EqualTo(Bar.Items.Item2)); + } + } + [Test] public void TestOverrideVirtualWithString() { diff --git a/tests/CSharp/CSharp.cpp b/tests/CSharp/CSharp.cpp index e7e46f0a..ea55a589 100644 --- a/tests/CSharp/CSharp.cpp +++ b/tests/CSharp/CSharp.cpp @@ -262,6 +262,26 @@ long Proprietor::prop() return m_property; } +Bar::Items Proprietor::items() const +{ + return _items; +} + +void Proprietor::setItems(const Bar::Items& value) +{ + _items = value; +} + +Bar::Items Proprietor::itemsByValue() const +{ + return _itemsByValue; +} + +void Proprietor::setItemsByValue(Bar::Items value) +{ + _itemsByValue = value; +} + void P::setValue(int value) { m_value = value + 10; diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index 48194b0f..0c41feef 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -159,9 +159,18 @@ public: virtual void setValue(int value); virtual long prop(); + + Bar::Items items() const; + void setItems(const Bar::Items& value); + + Bar::Items itemsByValue() const; + void setItemsByValue(Bar::Items value); +private: + Bar::Items _items; + Bar::Items _itemsByValue; }; -Proprietor::Proprietor() {} +Proprietor::Proprietor() : _items(Bar::Items::Item1), _itemsByValue(Bar::Items::Item1) {} template class DLL_API QFlags