diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index c0eff1cd..4d079c4a 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -278,7 +278,9 @@ namespace CppSharp.Generators.CSharp if (finalType.TryGetClass(out returnedClass) && returnedClass.IsDependent) Context.Return.Write($"({returnType.Visit(typePrinter)}) (object) "); - if (returnType.IsAddress()) + // these two aren't the same for members of templates + if (Context.Function?.OriginalReturnType.Type.Desugar().IsAddress() == true || + returnType.IsAddress()) Context.Return.Write(HandleReturnedPointer(@class, qualifiedClass)); else { diff --git a/tests/CSharp/CSharp.Tests.cs b/tests/CSharp/CSharp.Tests.cs index 51798884..aa93d980 100644 --- a/tests/CSharp/CSharp.Tests.cs +++ b/tests/CSharp/CSharp.Tests.cs @@ -1176,17 +1176,20 @@ public unsafe class CSharpTests templateWithIndexer["test"] = 15; Assert.That(templateWithIndexer["test"], Is.EqualTo(15)); } - using (var templateWithIndexer = new TemplateWithIndexer()) + using (var templateWithIndexer = new TemplateWithIndexer()) { - using (var t1 = new T1(10)) + using (var t2 = new T2()) { - templateWithIndexer[0] = t1; - Assert.That(templateWithIndexer[0].Field, Is.EqualTo(t1.Field)); + templateWithIndexer[0] = t2; + var item = templateWithIndexer[0]; + Assert.That(item.Field, Is.EqualTo(t2.Field)); + item.Field = 5; + Assert.That(templateWithIndexer[0].Field, Is.EqualTo(5)); } - using (var t1 = new T1(15)) + using (var t2 = new T2(15)) { - templateWithIndexer["test"] = t1; - Assert.That(templateWithIndexer["test"].Field, Is.EqualTo(t1.Field)); + templateWithIndexer["test"] = t2; + Assert.That(templateWithIndexer["test"].Field, Is.EqualTo(t2.Field)); } } } diff --git a/tests/CSharp/CSharpTemplates.cpp b/tests/CSharp/CSharpTemplates.cpp index 08bcaeaa..bbf955f1 100644 --- a/tests/CSharp/CSharpTemplates.cpp +++ b/tests/CSharp/CSharpTemplates.cpp @@ -1,29 +1,26 @@ #include "CSharpTemplates.h" -T1::T1() +T2::T2() : field(0) { } -T1::T1(const T1& other) : field(other.field) -{ -} - -T1::T1(int f) +T2::T2(int f) { field = f; } -T1::~T1() +T2::~T2() { } -int T1::getField() const +int T2::getField() const { return field; } -T2::T2() +void T2::setField(int value) { + field = value; } DerivedFromSpecializationOfUnsupportedTemplate::DerivedFromSpecializationOfUnsupportedTemplate() diff --git a/tests/CSharp/CSharpTemplates.h b/tests/CSharp/CSharpTemplates.h index dd891b7a..715e89ad 100644 --- a/tests/CSharp/CSharpTemplates.h +++ b/tests/CSharp/CSharpTemplates.h @@ -12,20 +12,18 @@ class DLL_API QString class DLL_API T1 { -public: - T1(); - T1(const T1& other); - T1(int f); - ~T1(); - int getField() const; -private: - int field; }; class DLL_API T2 { public: T2(); + T2(int f); + virtual ~T2(); + int getField() const; + void setField(int value); +private: + int field; }; class DLL_API Ignored @@ -92,7 +90,7 @@ IndependentFields::IndependentFields(float f) } template -IndependentFields::IndependentFields(const std::map &v) +IndependentFields::IndependentFields(const std::map &v) : independent(1) { }