diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index 42791bb0..8217848b 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -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 } 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(";"); } diff --git a/tests/CSharp/CSharp.cpp b/tests/CSharp/CSharp.cpp index 1e814dd7..6a4ee158 100644 --- a/tests/CSharp/CSharp.cpp +++ b/tests/CSharp/CSharp.cpp @@ -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); } diff --git a/tests/Common/Common.h b/tests/Common/Common.h index 2d7ba601..4521a20f 100644 --- a/tests/Common/Common.h +++ b/tests/Common/Common.h @@ -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: