Browse Source

Fixed a compilation error when having a setter match for an explicit interface getter.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/513/head
Dimitar Dobrev 10 years ago
parent
commit
45e4ba7782
  1. 20
      src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs
  2. 23
      tests/CSharpTemp/CSharpTemp.Tests.cs
  3. 4
      tests/CSharpTemp/CSharpTemp.cpp
  4. 1
      tests/CSharpTemp/CSharpTemp.h

20
src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs

@ -55,7 +55,9 @@ namespace CppSharp.Passes @@ -55,7 +55,9 @@ namespace CppSharp.Passes
if (char.IsLower(setter.Name[0]))
nameBuilder[0] = char.ToLowerInvariant(nameBuilder[0]);
string afterSet = nameBuilder.ToString();
foreach (var getter in nonSetters.Where(m => m.Namespace == type))
var s = setter;
foreach (var getter in nonSetters.Where(m => m.Namespace == type &&
m.ExplicitInterfaceImpl == s.ExplicitInterfaceImpl))
{
var name = GetReadWritePropertyName(getter, afterSet);
if (name == afterSet &&
@ -82,11 +84,11 @@ namespace CppSharp.Passes @@ -82,11 +84,11 @@ namespace CppSharp.Passes
goto next;
}
}
Property baseVirtualProperty = type.GetRootBaseProperty(new Property { Name = afterSet });
if (!type.IsInterface && baseVirtualProperty != null)
Property baseProperty = type.GetRootBaseProperty(new Property { Name = afterSet });
if (!type.IsInterface && baseProperty != null && baseProperty.IsVirtual && setter.IsVirtual)
{
bool isReadOnly = baseVirtualProperty.SetMethod == null;
GenerateProperty(setter.Namespace, baseVirtualProperty.GetMethod,
bool isReadOnly = baseProperty.SetMethod == null;
GenerateProperty(setter.Namespace, baseProperty.GetMethod,
readOnly || isReadOnly ? null : setter);
}
next:
@ -96,14 +98,14 @@ namespace CppSharp.Passes @@ -96,14 +98,14 @@ namespace CppSharp.Passes
{
Class type = (Class) nonSetter.Namespace;
string name = GetPropertyName(nonSetter.Name);
Property baseVirtualProperty = type.GetRootBaseProperty(new Property { Name = name });
if (!type.IsInterface && baseVirtualProperty != null)
Property baseProperty = type.GetRootBaseProperty(new Property { Name = name });
if (!type.IsInterface && baseProperty != null && baseProperty.IsVirtual)
{
bool isReadOnly = baseVirtualProperty.SetMethod == null;
bool isReadOnly = baseProperty.SetMethod == null;
if (readOnly == isReadOnly)
{
GenerateProperty(nonSetter.Namespace, nonSetter,
readOnly ? null : baseVirtualProperty.SetMethod);
readOnly ? null : baseProperty.SetMethod);
}
}
}

23
tests/CSharpTemp/CSharpTemp.Tests.cs

@ -50,16 +50,19 @@ public class CSharpTempTests : GeneratorTestFixture @@ -50,16 +50,19 @@ public class CSharpTempTests : GeneratorTestFixture
[Test]
public void TestMultipleInheritance()
{
var baz = new Baz();
Assert.That(baz.Method, Is.EqualTo(1));
var bar = (IBar) baz;
Assert.That(bar.Method, Is.EqualTo(2));
Assert.That(baz[0], Is.EqualTo(50));
bar[0] = new Foo { A = 1000 };
Assert.That(bar[0].A, Is.EqualTo(1000));
Assert.That(baz.FarAwayFunc, Is.EqualTo(20));
Assert.That(baz.TakesQux(baz), Is.EqualTo(20));
Assert.That(baz.ReturnQux().FarAwayFunc, Is.EqualTo(20));
using (var baz = new Baz())
{
Assert.That(baz.Method, Is.EqualTo(1));
var bar = (IBar) baz;
Assert.That(bar.Method, Is.EqualTo(2));
Assert.That(baz[0], Is.EqualTo(50));
bar[0] = new Foo { A = 1000 };
Assert.That(bar[0].A, Is.EqualTo(1000));
Assert.That(baz.FarAwayFunc, Is.EqualTo(20));
Assert.That(baz.TakesQux(baz), Is.EqualTo(20));
Assert.That(baz.ReturnQux().FarAwayFunc, Is.EqualTo(20));
baz.SetMethod(1);
}
}
[Test]

4
tests/CSharpTemp/CSharpTemp.cpp

@ -137,6 +137,10 @@ Qux Baz::returnQux() @@ -137,6 +137,10 @@ Qux Baz::returnQux()
return Qux();
}
void Baz::setMethod(int value)
{
}
int AbstractProprietor::getValue()
{
return m_value;

1
tests/CSharpTemp/CSharpTemp.h

@ -83,6 +83,7 @@ public: @@ -83,6 +83,7 @@ public:
int takesQux(const Qux& qux);
Qux returnQux();
void setMethod(int value);
typedef bool (*FunctionTypedef)(const void *);
FunctionTypedef functionTypedef;

Loading…
Cancel
Save