Browse Source

Fixed the binding of indexer overloads when there's more than one class key.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/862/head
Dimitar Dobrev 9 years ago
parent
commit
37adb3efc9
  1. 2
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 8
      tests/Common/Common.Tests.cs
  3. 5
      tests/Common/Common.cpp
  4. 1
      tests/Common/Common.h

2
src/Generator/Generators/CSharp/CSharpSources.cs

@ -2998,7 +2998,7 @@ namespace CppSharp.Generators.CSharp @@ -2998,7 +2998,7 @@ namespace CppSharp.Generators.CSharp
identifier.Append(Helpers.GetSuffixFor(specialization));
var overloads = function.Namespace.GetOverloads(function)
.Where(f => f.IsGenerated).ToList();
.Where(f => f.IsGenerated || f.OperatorKind == CXXOperatorKind.Subscript).ToList();
var index = overloads.IndexOf(function);
if (index >= 0)

8
tests/Common/Common.Tests.cs

@ -412,11 +412,19 @@ public class CommonTests : GeneratorTestFixture @@ -412,11 +412,19 @@ public class CommonTests : GeneratorTestFixture
Assert.AreEqual(4, newProperties.Field);
newProperties.Field = 5;
Assert.AreEqual(5, indexedProperties[(byte) 0].Field);
var bar = new Bar { A = 5 };
indexedProperties[0u] = bar;
Assert.That(bar.A, Is.EqualTo(indexedProperties[0u].A));
indexedProperties[(ushort) 0] = bar;
Assert.That(bar.A, Is.EqualTo(indexedProperties[(ushort) 0].A));
using (var foo = new Foo())
{
var bar2 = new Bar { A = 10 };
indexedProperties[foo] = bar2;
Assert.That(bar2.A, Is.EqualTo(indexedProperties[foo].A));
}
}
}

5
tests/Common/Common.cpp

@ -449,6 +449,11 @@ TypeMappedIndex::TypeMappedIndex() @@ -449,6 +449,11 @@ TypeMappedIndex::TypeMappedIndex()
{
}
Bar& TestIndexedProperties::operator[](const Foo& key)
{
return bar;
}
InternalCtorAmbiguity::InternalCtorAmbiguity(void* param)
{
// cause a crash to indicate this is the incorrect ctor to invoke

1
tests/Common/Common.h

@ -568,6 +568,7 @@ public: @@ -568,6 +568,7 @@ public:
foo_t operator[](TestProperties b);
Bar& operator[](unsigned long i);
Bar& operator[](const TypeMappedIndex& key);
Bar& operator[](const Foo& key);
// Test that we do not generate 'ref int' parameters as C# does not allow it
int operator[](CS_OUT char key);

Loading…
Cancel
Save