Browse Source

CreateInstance factory overload to pass flag informing wrapper if it should own the native pointer passed to it.

pull/1373/head
Build Agent 5 years ago committed by Dimitar Dobrev
parent
commit
e31dc22ab1
  1. 2
      src/Generator/Generators/CLI/CLIHeaders.cs
  2. 19
      src/Generator/Generators/CLI/CLISources.cs

2
src/Generator/Generators/CLI/CLIHeaders.cs

@ -380,6 +380,8 @@ namespace CppSharp.Generators.CLI @@ -380,6 +380,8 @@ namespace CppSharp.Generators.CLI
WriteLine("static {0}^ {1}(::System::IntPtr native);",
@class.Name, Helpers.CreateInstanceIdentifier);
WriteLine($"static {@class.Name}^ {Helpers.CreateInstanceIdentifier}(::System::IntPtr native, bool {Helpers.OwnsNativeInstanceIdentifier});");
foreach (var ctor in @class.Constructors)
{
if (ASTUtils.CheckIgnoreMethod(ctor) || FunctionIgnored(ctor))

19
src/Generator/Generators/CLI/CLISources.cs

@ -670,18 +670,21 @@ namespace CppSharp.Generators.CLI @@ -670,18 +670,21 @@ namespace CppSharp.Generators.CLI
UnindentAndWriteCloseBrace();
if (!withOwnNativeInstanceParam)
{
NewLine();
WriteLine("{0}^ {0}::{1}(::System::IntPtr native)", qualifiedIdentifier, Helpers.CreateInstanceIdentifier);
string createInstanceParams = withOwnNativeInstanceParam ? $"::System::IntPtr native, bool {Helpers.OwnsNativeInstanceIdentifier}" : "::System::IntPtr native";
string createInstanceParamsValues = withOwnNativeInstanceParam ? $"({nativeType}) native.ToPointer(), {Helpers.OwnsNativeInstanceIdentifier}" : $"({nativeType}) native.ToPointer()";
WriteOpenBraceAndIndent();
NewLine();
WriteLine($"{qualifiedIdentifier}^ {qualifiedIdentifier}::{Helpers.CreateInstanceIdentifier}({createInstanceParams})");
WriteLine("return gcnew ::{0}(({1}) native.ToPointer());", qualifiedIdentifier, nativeType);
WriteOpenBraceAndIndent();
UnindentAndWriteCloseBrace();
NewLine();
WriteLine($"return gcnew ::{qualifiedIdentifier}({createInstanceParamsValues});");
UnindentAndWriteCloseBrace();
NewLine();
if (!withOwnNativeInstanceParam)
{
GenerateClassConstructor(@class, true);
}
}

Loading…
Cancel
Save