Browse Source

Generate valid C# for variables with > 1 arg

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1641/head
Dimitar Dobrev 4 years ago
parent
commit
ac5001ddca
  1. 12
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 2
      tests/CSharp/CSharp.cpp
  3. 4
      tests/Common/Common.h

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

@ -1185,8 +1185,9 @@ namespace CppSharp.Generators.CSharp @@ -1185,8 +1185,9 @@ namespace CppSharp.Generators.CSharp
{
var initializerString = variable.Initializer.String;
Write($"{signature} {{ get; }} = ");
Type type = variable.Type.Desugar();
if (variable.Type.Desugar() is ArrayType arrayType)
if (type is ArrayType arrayType)
{
var systemType = Internal.ExpressionHelper.GetSystemType(Context, arrayType.Type.Desugar());
Write($"new {arrayType.Type}[{arrayType.Size}] ");
@ -1217,12 +1218,13 @@ namespace CppSharp.Generators.CSharp @@ -1217,12 +1218,13 @@ namespace CppSharp.Generators.CSharp
}
else
{
var systemType = Internal.ExpressionHelper.GetSystemType(Context, variable.Type.Desugar());
var systemType = Internal.ExpressionHelper.GetSystemType(Context, type);
if (!Internal.ExpressionHelper.TryParseExactLiteralExpression(ref initializerString, systemType))
Write($"({variable.Type})");
Write(initializerString);
Write(type.IsPrimitiveType() || type.IsEnum() ? $"({type}) {initializerString}" :
$"new {type}({initializerString})");
else
Write(initializerString);
}
WriteLine(";");
}

2
tests/CSharp/CSharp.cpp

@ -1539,7 +1539,7 @@ int TestArrays::virtualTakeArrays(Foo* arrayOfPointersToObjects[], int arrayOfPr @@ -1539,7 +1539,7 @@ int TestArrays::virtualTakeArrays(Foo* arrayOfPointersToObjects[], int arrayOfPr
return takeArrays(arrayOfPointersToObjects, arrayOfPrimitives, arrayOfObjects);
}
int TestArrays::virtualTakeArrays(Foo *fixedArrayOfPointersToObjects[], int fixedArrayOfPrimitives[], int *fixedArrayOfPointersToPrimitives[]) const
int TestArrays::virtualTakeArrays(Foo *fixedArrayOfPointersToObjects[3], int fixedArrayOfPrimitives[4], int *fixedArrayOfPointersToPrimitives[5]) const
{
return takeArrays(fixedArrayOfPointersToObjects, fixedArrayOfPrimitives, fixedArrayOfPointersToPrimitives);
}

4
tests/Common/Common.h

@ -491,12 +491,14 @@ namespace SomeNamespace @@ -491,12 +491,14 @@ namespace SomeNamespace
class Inlines
{
public:
Inlines(int param) {}
constexpr Inlines(int param, const char* name) {}
inline operator NamespacedAbstractImpl () const { return NamespacedAbstractImpl(); }
protected:
void protectedInlined() {}
};
constexpr Inlines constWithParams(5, "test");
class AbstractInlines
{
public:

Loading…
Cancel
Save