Browse Source

Fixed the generated C# for constant references to primitives.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1139/head
Dimitar Dobrev 7 years ago
parent
commit
0c87a77311
  1. 6
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 1
      tests/CSharp/CSharp.Tests.cs
  3. 5
      tests/CSharp/CSharp.cpp
  4. 1
      tests/CSharp/CSharp.h

6
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -186,8 +186,7 @@ namespace CppSharp.Generators.CSharp @@ -186,8 +186,7 @@ namespace CppSharp.Generators.CSharp
if (Context.Function != null &&
Context.Function.OperatorKind == CXXOperatorKind.Subscript)
{
if (type.IsPrimitiveType(primitive) ||
new QualifiedType(pointer, quals).IsConstRefToPrimitive())
if (type.IsPrimitiveType(primitive))
{
Context.Return.Write("*");
}
@ -199,6 +198,9 @@ namespace CppSharp.Generators.CSharp @@ -199,6 +198,9 @@ namespace CppSharp.Generators.CSharp
}
}
if (new QualifiedType(pointer, quals).IsConstRefToPrimitive())
Context.Return.Write("*");
Context.Return.Write(Context.ReturnVarName);
return true;
}

1
tests/CSharp/CSharp.Tests.cs

@ -54,6 +54,7 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -54,6 +54,7 @@ public unsafe class CSharpTests : GeneratorTestFixture
hasSecondaryBaseWithAbstractWithDefaultArg.Abstract();
hasSecondaryBaseWithAbstractWithDefaultArg.AbstractWithNoDefaultArg(foo);
}
Assert.That(foo.ReturnConstRef(), Is.EqualTo(5));
}
using (var hasOverride = new HasOverrideOfHasPropertyWithDerivedType())
hasOverride.CauseRenamingError();

5
tests/CSharp/CSharp.cpp

@ -60,6 +60,11 @@ void Foo::set_width(int value) @@ -60,6 +60,11 @@ void Foo::set_width(int value)
{
}
const int& Foo::returnConstRef()
{
return rename;
}
const int Foo::rename;
int Foo::makeFunctionCall()

1
tests/CSharp/CSharp.h

@ -26,6 +26,7 @@ public: @@ -26,6 +26,7 @@ public:
void takesStdVector(const std::vector<int>& vector);
int width();
void set_width(int value);
const int& returnConstRef();
static const int rename = 5;
static int makeFunctionCall();

Loading…
Cancel
Save