Browse Source

Fixed the generated C# for parameters initialized with {}.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1166/head
Dimitar Dobrev 7 years ago
parent
commit
c688330897
  1. 2
      src/Generator/Passes/HandleDefaultParamValuesPass.cs
  2. 1
      tests/CSharp/CSharp.Tests.cs
  3. 4
      tests/CSharp/CSharp.cpp
  4. 1
      tests/CSharp/CSharp.h

2
src/Generator/Passes/HandleDefaultParamValuesPass.cs

@ -194,7 +194,7 @@ namespace CppSharp.Passes @@ -194,7 +194,7 @@ namespace CppSharp.Passes
var method = (Method) expression.Declaration;
var expressionSupported = decl.IsValueType && method.Parameters.Count == 0;
if (expression.String.Contains('('))
if (expression.String.Contains('(') || expression.String.StartsWith("{"))
{
var argsBuilder = new StringBuilder("new ");
argsBuilder.Append(typePrinterResult);

1
tests/CSharp/CSharp.Tests.cs

@ -255,6 +255,7 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -255,6 +255,7 @@ public unsafe class CSharpTests : GeneratorTestFixture
methodsWithDefaultValues.DefaultDoubleWithoutF();
methodsWithDefaultValues.DefaultIntExpressionWithEnum();
methodsWithDefaultValues.DefaultCtorWithMoreThanOneArg();
methodsWithDefaultValues.DefaultEmptyBraces();
methodsWithDefaultValues.DefaultWithRefManagedLong();
methodsWithDefaultValues.DefaultWithFunctionCall();
methodsWithDefaultValues.DefaultWithPropertyCall();

4
tests/CSharp/CSharp.cpp

@ -693,6 +693,10 @@ void MethodsWithDefaultValues::defaultCtorWithMoreThanOneArg(QMargins m) @@ -693,6 +693,10 @@ void MethodsWithDefaultValues::defaultCtorWithMoreThanOneArg(QMargins m)
{
}
void MethodsWithDefaultValues::defaultEmptyBraces(Foo foo)
{
}
void MethodsWithDefaultValues::defaultWithComplexArgs(const QRect& rectangle)
{
}

1
tests/CSharp/CSharp.h

@ -439,6 +439,7 @@ public: @@ -439,6 +439,7 @@ public:
void defaultDoubleWithoutF(double d1 = 1.0, double d2 = 1.);
void defaultIntExpressionWithEnum(int i = Qt::GlobalColor::black + 1);
void defaultCtorWithMoreThanOneArg(QMargins m = QMargins(0, 0, 0, 0));
void defaultEmptyBraces(Foo foo = {});
void defaultWithComplexArgs(const QRect& rectangle = QRect(QPoint(0, 0), QSize(-1, -1)));
void defaultWithRefManagedLong(long long* i = 0);
void defaultWithFunctionCall(int f = Foo::makeFunctionCall());

Loading…
Cancel
Save