From a1ddbd82d756b28023004369ed583a337f56e384 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sat, 30 May 2020 03:40:45 +0300 Subject: [PATCH] Expose returned values of non-void setters Now we generate them as methods too. Fixes https://github.com/mono/CppSharp/issues/960. Signed-off-by: Dimitar Dobrev --- src/Generator/Passes/GetterSetterToPropertyPass.cs | 3 ++- tests/Common/Common.Tests.cs | 4 ++++ tests/Common/Common.cpp | 2 +- tests/Common/Common.h | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Generator/Passes/GetterSetterToPropertyPass.cs b/src/Generator/Passes/GetterSetterToPropertyPass.cs index 0c2d89c2..fde5aa24 100644 --- a/src/Generator/Passes/GetterSetterToPropertyPass.cs +++ b/src/Generator/Passes/GetterSetterToPropertyPass.cs @@ -214,7 +214,8 @@ namespace CppSharp.Passes conflict.GetMethod = null; property.GetMethod.GenerationKind = GenerationKind.Internal; - if (property.SetMethod != null) + if (property.SetMethod != null && + property.SetMethod.OriginalReturnType.Type.Desugar().IsPrimitiveType(PrimitiveType.Void)) property.SetMethod.GenerationKind = GenerationKind.Internal; property.Namespace = @class; @class.Properties.Add(property); diff --git a/tests/Common/Common.Tests.cs b/tests/Common/Common.Tests.cs index 4077b519..b5dee8f7 100644 --- a/tests/Common/Common.Tests.cs +++ b/tests/Common/Common.Tests.cs @@ -551,9 +551,13 @@ public class CommonTests : GeneratorTestFixture prop.SetterReturnsBoolean = 35; Assert.That(prop.SetterReturnsBoolean, Is.EqualTo(35)); + Assert.That(prop.SetSetterReturnsBoolean(35), Is.False); + Assert.That(prop.SetSetterReturnsBoolean(40), Is.True); prop.VirtualSetterReturnsBoolean = 45; Assert.That(prop.VirtualSetterReturnsBoolean, Is.EqualTo(45)); + Assert.That(prop.SetVirtualSetterReturnsBoolean(45), Is.False); + Assert.That(prop.SetVirtualSetterReturnsBoolean(50), Is.True); Assert.That(prop.nestedEnum(), Is.EqualTo(5)); Assert.That(prop.nestedEnum(55), Is.EqualTo(55)); diff --git a/tests/Common/Common.cpp b/tests/Common/Common.cpp index 2a73fe11..d3ceba4b 100644 --- a/tests/Common/Common.cpp +++ b/tests/Common/Common.cpp @@ -631,7 +631,7 @@ int TestProperties::setterReturnsBoolean() return _setterReturnsBoolean; } -bool TestProperties::setterReturnsBoolean(int value) +bool TestProperties::setSetterReturnsBoolean(int value) { bool changed = _setterReturnsBoolean != value; _setterReturnsBoolean = value; diff --git a/tests/Common/Common.h b/tests/Common/Common.h index 321b2400..b0422a6c 100644 --- a/tests/Common/Common.h +++ b/tests/Common/Common.h @@ -623,7 +623,7 @@ public: void set(int value); int setterReturnsBoolean(); - bool setterReturnsBoolean(int value); + bool setSetterReturnsBoolean(int value); virtual int virtualSetterReturnsBoolean(); virtual bool setVirtualSetterReturnsBoolean(int value);