Browse Source

Fix bug related to processing of potential property methods.

Fixes https://github.com/mono/CppSharp/issues/1291.
pull/1261/merge
João Matos 6 years ago
parent
commit
40ca6f281a
  1. 3
      src/Generator/Passes/GetterSetterToPropertyPass.cs
  2. 4
      tests/Common/Common.Tests.cs
  3. 14
      tests/Common/Common.cpp
  4. 5
      tests/Common/Common.h

3
src/Generator/Passes/GetterSetterToPropertyPass.cs

@ -303,7 +303,8 @@ namespace CppSharp.Passes
private static string GetPropertyName(string name) private static string GetPropertyName(string name)
{ {
var firstWord = GetFirstWord(name); var firstWord = GetFirstWord(name);
if (Match(firstWord, new[] { "get" }) && name != firstWord && if (Match(firstWord, new[] { "get" }) &&
(string.Compare(name, firstWord, StringComparison.InvariantCultureIgnoreCase) != 0) &&
!char.IsNumber(name[3])) !char.IsNumber(name[3]))
{ {
if (char.IsLower(name[0])) if (char.IsLower(name[0]))

4
tests/Common/Common.Tests.cs

@ -450,6 +450,10 @@ public class CommonTests : GeneratorTestFixture
Assert.AreEqual(4, newProperties.Field); Assert.AreEqual(4, newProperties.Field);
newProperties.Field = 5; newProperties.Field = 5;
Assert.AreEqual(5, indexedProperties[(byte) 0].Field); Assert.AreEqual(5, indexedProperties[(byte) 0].Field);
newProperties.get();
newProperties.set(0);
newProperties.Get();
newProperties.Set(0);
var bar = new Bar { A = 5 }; var bar = new Bar { A = 5 };
indexedProperties[0u] = bar; indexedProperties[0u] = bar;

14
tests/Common/Common.cpp

@ -591,10 +591,24 @@ void TestProperties::getterAndSetterWithTheSameName(int value)
_getterAndSetterWithTheSameName = value; _getterAndSetterWithTheSameName = value;
} }
int TestProperties::get() const
{
return 3;
}
void TestProperties::set(int value) void TestProperties::set(int value)
{ {
} }
int TestProperties::Get() const
{
return 3;
}
void TestProperties::Set(int value)
{
}
int TestProperties::setterReturnsBoolean() int TestProperties::setterReturnsBoolean()
{ {
return _setterReturnsBoolean; return _setterReturnsBoolean;

5
tests/Common/Common.h

@ -605,6 +605,10 @@ public:
int getterAndSetterWithTheSameName(); int getterAndSetterWithTheSameName();
void getterAndSetterWithTheSameName(int value); void getterAndSetterWithTheSameName(int value);
int Get() const;
void Set(int value);
int get() const;
void set(int value); void set(int value);
int setterReturnsBoolean(); int setterReturnsBoolean();
@ -630,6 +634,7 @@ public:
bool contains(char c); bool contains(char c);
bool contains(const char* str); bool contains(const char* str);
private: private:
int FieldValue; int FieldValue;
double _refToPrimitiveInSetter; double _refToPrimitiveInSetter;

Loading…
Cancel
Save