Browse Source

Pass native pointers to bases in the generated C#

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1363/head
Dimitar Dobrev 5 years ago
parent
commit
0da9c46a73
  1. 12
      src/Generator/Generators/CSharp/CSharpSources.cs

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

@ -2186,7 +2186,7 @@ namespace CppSharp.Generators.CSharp @@ -2186,7 +2186,7 @@ namespace CppSharp.Generators.CSharp
var hasBaseClass = @class.HasBaseClass && @class.BaseClass.IsRefType;
if (hasBaseClass)
WriteLineIndent(": base((void*) null)", @class.BaseClass.Visit(TypePrinter));
WriteLineIndent(": base((void*) native)", @class.BaseClass.Visit(TypePrinter));
WriteOpenBraceAndIndent();
@ -2195,15 +2195,15 @@ namespace CppSharp.Generators.CSharp @@ -2195,15 +2195,15 @@ namespace CppSharp.Generators.CSharp
if (@class.BaseClass?.Layout.HasSubclassAtNonZeroOffset == true)
WriteLine("{0} = {1};", Helpers.PrimaryBaseOffsetIdentifier,
GetOffsetToBase(@class, @class.BaseClass));
if (!@class.IsAbstractImpl)
var hasVTables = @class.IsDynamic && GetUniqueVTableMethodEntries(@class).Count > 0;
if (!hasBaseClass || hasVTables)
{
WriteLine("if (native == null)");
WriteLineIndent("return;");
if (!hasBaseClass)
WriteLine($"{Helpers.InstanceIdentifier} = new global::System.IntPtr(native);");
}
WriteLine("{0} = new global::System.IntPtr(native);", Helpers.InstanceIdentifier);
var dtor = @class.Destructors.FirstOrDefault();
var hasVTables = @class.IsDynamic && GetUniqueVTableMethodEntries(@class).Count > 0;
var setupVTables = !@class.IsAbstractImpl && hasVTables && dtor?.IsVirtual == true;
if (setupVTables)
{
@ -2223,7 +2223,7 @@ namespace CppSharp.Generators.CSharp @@ -2223,7 +2223,7 @@ namespace CppSharp.Generators.CSharp
Unindent();
}
}
else
else if (!hasBaseClass)
{
WriteLine($"{Helpers.InstanceField} = *({TypePrinter.PrintNative(@class)}*) native;");
}

Loading…
Cancel
Save