Browse Source

Fixed the generated C# when an operator returns a template.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/890/head
Dimitar Dobrev 8 years ago
parent
commit
dd885a7541
  1. 8
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 14
      tests/CSharp/CSharp.Tests.cs
  3. 9
      tests/CSharp/CSharpTemplates.h

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

@ -2301,7 +2301,7 @@ namespace CppSharp.Generators.CSharp
} }
else if (method.IsOperator) else if (method.IsOperator)
{ {
GenerateOperator(method); GenerateOperator(method, returnType);
} }
else if (method.SynthKind == FunctionSynthKind.AbstractImplCall) else if (method.SynthKind == FunctionSynthKind.AbstractImplCall)
{ {
@ -2324,7 +2324,7 @@ namespace CppSharp.Generators.CSharp
} }
else if (method.IsOperator) else if (method.IsOperator)
{ {
GenerateOperator(method); GenerateOperator(method, returnType);
} }
else else
{ {
@ -2482,7 +2482,7 @@ namespace CppSharp.Generators.CSharp
return delegateId; return delegateId;
} }
private void GenerateOperator(Method method) private void GenerateOperator(Method method, QualifiedType returnType)
{ {
if (method.SynthKind == FunctionSynthKind.ComplementOperator) if (method.SynthKind == FunctionSynthKind.ComplementOperator)
{ {
@ -2533,7 +2533,7 @@ namespace CppSharp.Generators.CSharp
method.OperatorKind == CXXOperatorKind.EqualEqual ? string.Empty : ")"); method.OperatorKind == CXXOperatorKind.EqualEqual ? string.Empty : ")");
} }
GenerateInternalFunctionCall(method); GenerateInternalFunctionCall(method, returnType: returnType);
} }
private void GenerateClassConstructor(Method method, Class @class) private void GenerateClassConstructor(Method method, Class @class)

14
tests/CSharp/CSharp.Tests.cs

@ -799,6 +799,20 @@ public unsafe class CSharpTests : GeneratorTestFixture
} }
} }
[Test]
public void TestOperatorReturnTemplateValue()
{
using (var dependentValueFields = new DependentValueFields<int>())
{
using (var other = new DependentValueFields<int>())
{
dependentValueFields.DependentValue = 10;
other.DependentValue = 15;
Assert.That((dependentValueFields + other).DependentValue, Is.EqualTo(25));
}
}
}
[Test] [Test]
public void TestAbstractImplementatonsInPrimaryAndSecondaryBases() public void TestAbstractImplementatonsInPrimaryAndSecondaryBases()
{ {

9
tests/CSharp/CSharpTemplates.h

@ -115,6 +115,7 @@ public:
~DependentValueFields(); ~DependentValueFields();
DependentValueFields& returnInjectedClass(); DependentValueFields& returnInjectedClass();
DependentValueFields returnValue(); DependentValueFields returnValue();
DependentValueFields operator+(const DependentValueFields& other);
T getDependentValue(); T getDependentValue();
void setDependentValue(const T& value); void setDependentValue(const T& value);
private: private:
@ -158,6 +159,14 @@ DependentValueFields<T> DependentValueFields<T>::returnValue()
return *this; return *this;
} }
template <typename T>
DependentValueFields<T> DependentValueFields<T>::operator+(const DependentValueFields& other)
{
DependentValueFields<T> sum;
sum.field = field + other.field;
return sum;
}
template <typename T> template <typename T>
class DLL_API DependentPointerFields class DLL_API DependentPointerFields
{ {

Loading…
Cancel
Save