diff --git a/src/Generator/Passes/GetterSetterToPropertyPass.cs b/src/Generator/Passes/GetterSetterToPropertyPass.cs index 1cf1a5e7..2ce42522 100644 --- a/src/Generator/Passes/GetterSetterToPropertyPass.cs +++ b/src/Generator/Passes/GetterSetterToPropertyPass.cs @@ -143,27 +143,8 @@ namespace CppSharp.Passes { foreach (var property in newProperties) { - if (property.IsOverride) - { - Property baseProperty = GetBaseProperty(@class, property); - if (baseProperty == null) - { - if (property.SetMethod != null) - { - property.SetMethod.GenerationKind = GenerationKind.Generate; - property.SetMethod = null; - } - else - { - property.GetMethod.GenerationKind = GenerationKind.Generate; - property.GetMethod = null; - } - } - else if (property.GetMethod == null && baseProperty.SetMethod != null) - property.GetMethod = baseProperty.GetMethod; - else if (property.SetMethod == null) - property.SetMethod = baseProperty.SetMethod; - } + ProcessOverridden(@class, property); + if (property.GetMethod == null) { if (property.SetMethod != null) @@ -185,14 +166,45 @@ namespace CppSharp.Passes } } + private static void ProcessOverridden(Class @class, Property property) + { + if (!property.IsOverride) + return; + + Property baseProperty = GetBaseProperty(@class, property); + if (baseProperty == null) + { + if (property.SetMethod != null) + { + property.SetMethod.GenerationKind = GenerationKind.Generate; + property.SetMethod = null; + } + else + { + property.GetMethod.GenerationKind = GenerationKind.Generate; + property.GetMethod = null; + } + } + else if (property.GetMethod == null && baseProperty.SetMethod != null) + property.GetMethod = baseProperty.GetMethod; + else if (property.SetMethod == null || baseProperty.SetMethod == null) + { + if (property.SetMethod != null) + property.SetMethod.GenerationKind = GenerationKind.Generate; + property.SetMethod = baseProperty.SetMethod; + } + } + private static Property GetBaseProperty(Class @class, Property @override) { foreach (var @base in @class.Bases) { Class baseClass = @base.Class.OriginalClass ?? @base.Class; Property baseProperty = baseClass.Properties.Find(p => - (@override.GetMethod != null && @override.GetMethod.BaseMethod == p.GetMethod) || - (@override.SetMethod != null && @override.SetMethod.BaseMethod == p.SetMethod) || + (@override.GetMethod?.IsOverride == true && + @override.GetMethod.BaseMethod == p.GetMethod) || + (@override.SetMethod?.IsOverride == true && + @override.SetMethod.BaseMethod == p.SetMethod) || (@override.Field != null && @override.Field == p.Field)); if (baseProperty != null) return baseProperty; diff --git a/tests/Common/Common.Tests.cs b/tests/Common/Common.Tests.cs index 40f50985..13531435 100644 --- a/tests/Common/Common.Tests.cs +++ b/tests/Common/Common.Tests.cs @@ -522,6 +522,13 @@ public class CommonTests : GeneratorTestFixture Assert.That(prop.Get32Bit, Is.EqualTo(10)); Assert.That(prop.IsEmpty, Is.EqualTo(prop.Empty)); + + Assert.That(prop.VirtualGetter, Is.EqualTo(15)); + } + using (var prop = new HasOverridenSetter()) + { + Assert.That(prop.VirtualGetter, Is.EqualTo(20)); + prop.SetVirtualGetter(5); } } diff --git a/tests/Common/Common.cpp b/tests/Common/Common.cpp index 094f4efe..ca71d095 100644 --- a/tests/Common/Common.cpp +++ b/tests/Common/Common.cpp @@ -628,6 +628,11 @@ bool TestProperties::empty() return false; } +int TestProperties::virtualGetter() +{ + return 15; +} + HasOverridenSetter::HasOverridenSetter() { } @@ -646,6 +651,15 @@ bool HasOverridenSetter::setVirtualSetterReturnsBoolean(int value) return TestProperties::setVirtualSetterReturnsBoolean(value); } +int HasOverridenSetter::virtualGetter() +{ + return 20; +} + +void HasOverridenSetter::setVirtualGetter(int value) +{ +} + TypeMappedIndex::TypeMappedIndex() { } diff --git a/tests/Common/Common.h b/tests/Common/Common.h index 9e3153c8..7ab93c08 100644 --- a/tests/Common/Common.h +++ b/tests/Common/Common.h @@ -614,6 +614,8 @@ public: int get32Bit(); bool isEmpty(); bool empty(); + + virtual int virtualGetter(); private: int FieldValue; double _refToPrimitiveInSetter; @@ -630,6 +632,9 @@ public: int virtualSetterReturnsBoolean() override; bool setVirtualSetterReturnsBoolean(int value) override; + + int virtualGetter() override; + void setVirtualGetter(int value); }; class DLL_API TypeMappedIndex