Browse Source

Generate valid C# for copy ctors with extra args

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

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

@ -2501,7 +2501,11 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty @@ -2501,7 +2501,11 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
// Allocate memory for a new native object and call the ctor.
WriteLine($"var ret = Marshal.AllocHGlobal(sizeof({@internal}));");
var printed = TypePrinter.PrintNative(@class);
WriteLine($"{printed}.{GetFunctionNativeIdentifier(copyCtorMethod)}(ret, new {TypePrinter.IntPtrType}(&native));",
string defaultValue = string.Empty;
if (copyCtorMethod.Parameters.Count > 1)
defaultValue = $", {ExpressionPrinter.VisitParameter(copyCtorMethod.Parameters.Last())}";
WriteLine($@"{printed}.{GetFunctionNativeIdentifier(copyCtorMethod)}(ret, new {
TypePrinter.IntPtrType}(&native){defaultValue});",
printed, GetFunctionNativeIdentifier(copyCtorMethod));
WriteLine("return ret.ToPointer();");
}

5
tests/Common/Common.cpp

@ -465,6 +465,11 @@ ClassA::ClassA(int value) @@ -465,6 +465,11 @@ ClassA::ClassA(int value)
Value = value;
}
ClassA::ClassA(const ClassA& other, bool param)
{
Value = other.Value;
}
ClassB::ClassB(const ClassA& x)
{
Value = x.Value;

1
tests/Common/Common.h

@ -713,6 +713,7 @@ class DLL_API ClassA @@ -713,6 +713,7 @@ class DLL_API ClassA
{
public:
ClassA(int value);
ClassA(const ClassA& other, bool param = true);
int Value;
};
class DLL_API ClassB

Loading…
Cancel
Save