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 @@ -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 @@ -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 @@ -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 @@ -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)

14
tests/CSharp/CSharp.Tests.cs

@ -799,6 +799,20 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -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]
public void TestAbstractImplementatonsInPrimaryAndSecondaryBases()
{

9
tests/CSharp/CSharpTemplates.h

@ -115,6 +115,7 @@ public: @@ -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<T> DependentValueFields<T>::returnValue() @@ -158,6 +159,14 @@ DependentValueFields<T> DependentValueFields<T>::returnValue()
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>
class DLL_API DependentPointerFields
{

Loading…
Cancel
Save