Browse Source

Fixed the generated C# for fixed arrays of Booleans.

fixes #1004

* mend

Fixed the generated C# for fixed arrays of Booleans
pull/990/head
Mikulas Florek 8 years ago committed by Dimitar Dobrev
parent
commit
04a1591e84
  1. 11
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 18
      tests/CSharp/CSharp.Tests.cs
  3. 2
      tests/CSharp/CSharp.h

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

@ -115,7 +115,10 @@ namespace CppSharp.Generators.CSharp @@ -115,7 +115,10 @@ namespace CppSharp.Generators.CSharp
}
else
{
if (arrayType.IsPrimitiveType(PrimitiveType.Char) &&
if (arrayType.IsPrimitiveType(PrimitiveType.Bool))
supportBefore.WriteLineIndent($@"{value}[i] = {
Context.ReturnVarName}[i] != 0;");
else if (arrayType.IsPrimitiveType(PrimitiveType.Char) &&
Context.Context.Options.MarshalCharAsManagedChar)
supportBefore.WriteLineIndent($@"{value}[i] = global::System.Convert.ToChar({
Context.ReturnVarName}[i]);");
@ -514,7 +517,11 @@ namespace CppSharp.Generators.CSharp @@ -514,7 +517,11 @@ namespace CppSharp.Generators.CSharp
}
else
{
if (arrayType.IsPrimitiveType(PrimitiveType.Char) &&
if (arrayType.IsPrimitiveType(PrimitiveType.Bool))
supportBefore.WriteLineIndent($@"{
Context.ReturnVarName}[i] = (byte)({
Context.ArgName}[i] ? 1 : 0);");
else if (arrayType.IsPrimitiveType(PrimitiveType.Char) &&
Context.Context.Options.MarshalCharAsManagedChar)
supportBefore.WriteLineIndent($@"{
Context.ReturnVarName}[i] = global::System.Convert.ToSByte({

18
tests/CSharp/CSharp.Tests.cs

@ -281,6 +281,24 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -281,6 +281,24 @@ public unsafe class CSharpTests : GeneratorTestFixture
}
}
[Test]
public void TestBooleanArray()
{
Foo foo = new Foo { A = 10 };
var new_values = new bool[5];
for(int i = 0; i < new_values.Length; ++i)
{
new_values[i] = i % 2 == 0;
}
foo.Btest = new_values;
Assert.AreEqual(true, foo.Btest[0]);
Assert.AreEqual(false, foo.Btest[1]);
Assert.AreEqual(true, foo.Btest[2]);
Assert.AreEqual(false, foo.Btest[3]);
Assert.AreEqual(true, foo.Btest[4]);
}
[Test]
public void TestImplicitCtor()
{

2
tests/CSharp/CSharp.h

@ -32,6 +32,8 @@ public: @@ -32,6 +32,8 @@ public:
int operator ++();
int operator --();
bool btest[5];
protected:
int P;
TemplateInAnotherUnit<int> templateInAnotherUnit;

Loading…
Cancel
Save