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. 10
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 2
      tests/CSharp/CSharp.cpp
  3. 4
      tests/Common/Common.h

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

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

2
tests/CSharp/CSharp.cpp

@ -1539,7 +1539,7 @@ int TestArrays::virtualTakeArrays(Foo* arrayOfPointersToObjects[], int arrayOfPr
return takeArrays(arrayOfPointersToObjects, arrayOfPrimitives, arrayOfObjects); 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); return takeArrays(fixedArrayOfPointersToObjects, fixedArrayOfPrimitives, fixedArrayOfPointersToPrimitives);
} }

4
tests/Common/Common.h

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

Loading…
Cancel
Save