@ -250,6 +250,8 @@ namespace CppSharp.Generators.CLI
@@ -250,6 +250,8 @@ namespace CppSharp.Generators.CLI
WriteLine ( "{0}::~{1}()" , QualifiedIdentifier ( @class ) , @class . Name ) ;
WriteOpenBraceAndIndent ( ) ;
PushBlock ( BlockKind . DestructorBody , @class ) ;
if ( CLIGenerator . ShouldGenerateClassNativeField ( @class ) )
{
WriteLine ( "delete NativePtr;" ) ;
@ -264,6 +266,8 @@ namespace CppSharp.Generators.CLI
@@ -264,6 +266,8 @@ namespace CppSharp.Generators.CLI
UnindentAndWriteCloseBrace ( ) ;
}
PopBlock ( ) ;
UnindentAndWriteCloseBrace ( ) ;
PopBlock ( NewLineKind . BeforeNextBlock ) ;
@ -276,9 +280,13 @@ namespace CppSharp.Generators.CLI
@@ -276,9 +280,13 @@ namespace CppSharp.Generators.CLI
WriteLine ( "{0}::!{1}()" , QualifiedIdentifier ( @class ) , @class . Name ) ;
WriteOpenBraceAndIndent ( ) ;
PushBlock ( BlockKind . FinalizerBody , @class ) ;
if ( CLIGenerator . ShouldGenerateClassNativeField ( @class ) )
WriteLine ( "delete NativePtr;" ) ;
PopBlock ( ) ;
UnindentAndWriteCloseBrace ( ) ;
PopBlock ( NewLineKind . BeforeNextBlock ) ;
@ -618,16 +626,16 @@ namespace CppSharp.Generators.CLI
@@ -618,16 +626,16 @@ namespace CppSharp.Generators.CLI
GeneratePropertySetter ( variable , @class , variable . Name , variable . Type ) ;
}
private void GenerateClassConstructor ( Class @class )
private void GenerateClassConstructor ( Class @class , bool withOwnNativeInstanceParam = false )
{
string qualifiedIdentifier = QualifiedIdentifier ( @class ) ;
Write ( "{0}::{1}(" , qualifiedIdentifier , @class . Name ) ;
var nativeType = string . Format ( "::{0}*" , @class . QualifiedOriginalName ) ;
WriteLine ( "{0} native)" , nativeType ) ;
WriteLine ( ! withOwnNativeInstanceParam ? "{0} native)" : "{0} native, const bool ownNativeInstanc e)" , nativeType ) ;
var hasBase = GenerateClassConstructorBase ( @class ) ;
var hasBase = GenerateClassConstructorBase ( @class , null , withOwnNativeInstanceParam ) ;
if ( CLIGenerator . ShouldGenerateClassNativeField ( @class ) )
{
@ -635,11 +643,13 @@ namespace CppSharp.Generators.CLI
@@ -635,11 +643,13 @@ namespace CppSharp.Generators.CLI
Write ( hasBase ? "," : ":" ) ;
Unindent ( ) ;
WriteLine ( " {0}(false)" , Helpers . OwnsNativeInstanceIdentifier ) ;
WriteLine ( ! withOwnNativeInstanceParam ? " {0}(false)" : " {0}(ownNativeInstanc e)" , Helpers . OwnsNativeInstanceIdentifier ) ;
}
WriteOpenBraceAndIndent ( ) ;
PushBlock ( BlockKind . ConstructorBody , @class ) ;
const string nativePtr = "native" ;
if ( @class . IsRefType )
@ -654,16 +664,24 @@ namespace CppSharp.Generators.CLI
@@ -654,16 +664,24 @@ namespace CppSharp.Generators.CLI
GenerateStructMarshaling ( @class , nativePtr + "->" ) ;
}
PopBlock ( ) ;
UnindentAndWriteCloseBrace ( ) ;
NewLine ( ) ;
WriteLine ( "{0}^ {0}::{1}(::System::IntPtr native)" , qualifiedIdentifier , Helpers . CreateInstanceIdentifier ) ;
WriteOpenBraceAndIndent ( ) ;
if ( ! withOwnNativeInstanceParam )
{
NewLine ( ) ;
WriteLine ( "{0}^ {0}::{1}(::System::IntPtr native)" , qualifiedIdentifier , Helpers . CreateInstanceIdentifier ) ;
WriteLine ( "return gcnew ::{0}(({1}) native.ToPointer());" , qualifiedIdentifier , nativeType ) ;
WriteOpenBraceAndIndent ( ) ;
UnindentAndWriteCloseBrace ( ) ;
NewLine ( ) ;
WriteLine ( "return gcnew ::{0}(({1}) native.ToPointer());" , qualifiedIdentifier , nativeType ) ;
UnindentAndWriteCloseBrace ( ) ;
NewLine ( ) ;
GenerateClassConstructor ( @class , true ) ;
}
}
private void GenerateStructMarshaling ( Class @class , string nativeVar )
@ -701,7 +719,7 @@ namespace CppSharp.Generators.CLI
@@ -701,7 +719,7 @@ namespace CppSharp.Generators.CLI
}
}
private bool GenerateClassConstructorBase ( Class @class , Method method = null )
private bool GenerateClassConstructorBase ( Class @class , Method method = null , bool withOwnNativeInstanceParam = false )
{
var hasBase = @class . HasBase & & @class . Bases [ 0 ] . IsClass & & @class . Bases [ 0 ] . Class . IsGenerated ;
if ( ! hasBase )
@ -720,7 +738,7 @@ namespace CppSharp.Generators.CLI
@@ -720,7 +738,7 @@ namespace CppSharp.Generators.CLI
var nativeTypeName = baseClass . Visit ( cppTypePrinter ) ;
Write ( "({0}*)" , nativeTypeName ) ;
WriteLine ( "{0})" , method ! = null ? "nullptr" : "native" ) ;
WriteLine ( "{0}{1} )" , method ! = null ? "nullptr" : "native" , ! withOwnNativeInstanceParam ? "" : ", ownNativeInstanc e" ) ;
Unindent ( ) ;
}
@ -754,7 +772,11 @@ namespace CppSharp.Generators.CLI
@@ -754,7 +772,11 @@ namespace CppSharp.Generators.CLI
PushBlock ( BlockKind . MethodBody , method ) ;
if ( method . IsConstructor & & @class . IsRefType )
{
PushBlock ( BlockKind . ConstructorBody , @class ) ;
WriteLine ( "{0} = true;" , Helpers . OwnsNativeInstanceIdentifier ) ;
}
if ( method . IsProxy )
goto SkipImpl ;
@ -770,6 +792,8 @@ namespace CppSharp.Generators.CLI
@@ -770,6 +792,8 @@ namespace CppSharp.Generators.CLI
GenerateFunctionParams ( @params ) ;
WriteLine ( ");" ) ;
}
PopBlock ( ) ;
}
else
{