diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index 6b348430..c0d9d63e 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -2301,7 +2301,7 @@ namespace CppSharp.Generators.CSharp } else if (method.IsOperator) { - GenerateOperator(method); + GenerateOperator(method, returnType); } else if (method.SynthKind == FunctionSynthKind.AbstractImplCall) { @@ -2324,7 +2324,7 @@ namespace CppSharp.Generators.CSharp } else if (method.IsOperator) { - GenerateOperator(method); + GenerateOperator(method, returnType); } else { @@ -2482,7 +2482,7 @@ namespace CppSharp.Generators.CSharp return delegateId; } - private void GenerateOperator(Method method) + private void GenerateOperator(Method method, QualifiedType returnType) { if (method.SynthKind == FunctionSynthKind.ComplementOperator) { @@ -2533,7 +2533,7 @@ namespace CppSharp.Generators.CSharp method.OperatorKind == CXXOperatorKind.EqualEqual ? string.Empty : ")"); } - GenerateInternalFunctionCall(method); + GenerateInternalFunctionCall(method, returnType: returnType); } private void GenerateClassConstructor(Method method, Class @class) diff --git a/tests/CSharp/CSharp.Tests.cs b/tests/CSharp/CSharp.Tests.cs index 7cb99a2c..b517c551 100644 --- a/tests/CSharp/CSharp.Tests.cs +++ b/tests/CSharp/CSharp.Tests.cs @@ -799,6 +799,20 @@ public unsafe class CSharpTests : GeneratorTestFixture } } + [Test] + public void TestOperatorReturnTemplateValue() + { + using (var dependentValueFields = new DependentValueFields()) + { + using (var other = new DependentValueFields()) + { + dependentValueFields.DependentValue = 10; + other.DependentValue = 15; + Assert.That((dependentValueFields + other).DependentValue, Is.EqualTo(25)); + } + } + } + [Test] public void TestAbstractImplementatonsInPrimaryAndSecondaryBases() { diff --git a/tests/CSharp/CSharpTemplates.h b/tests/CSharp/CSharpTemplates.h index 71c555d2..d734f69d 100644 --- a/tests/CSharp/CSharpTemplates.h +++ b/tests/CSharp/CSharpTemplates.h @@ -115,6 +115,7 @@ public: ~DependentValueFields(); DependentValueFields& returnInjectedClass(); DependentValueFields returnValue(); + DependentValueFields operator+(const DependentValueFields& other); T getDependentValue(); void setDependentValue(const T& value); private: @@ -158,6 +159,14 @@ DependentValueFields DependentValueFields::returnValue() return *this; } +template +DependentValueFields DependentValueFields::operator+(const DependentValueFields& other) +{ + DependentValueFields sum; + sum.field = field + other.field; + return sum; +} + template class DLL_API DependentPointerFields {