@@ -768,41 +768,54 @@ private void MarshalRefClass(Class @class)
768
768
{
769
769
if ( Context . Parameter . IsIndirect )
770
770
{
771
- Method cctor = @class . HasNonTrivialCopyConstructor ? @class . Methods . First ( c => c . IsCopyConstructor ) : null ;
772
- if ( cctor != null && cctor . IsGenerated )
771
+ // Kythera-specific classes.
772
+ if ( @class . Namespace . Name == "Kyt" )
773
773
{
774
- Context . Before . WriteLine ( $ "if (ReferenceEquals({ Context . Parameter . Name } , null))") ;
775
- Context . Before . WriteLineIndent (
776
- $@ "throw new global::System.ArgumentNullException(""{
777
- Context . Parameter . Name } "", ""Cannot be null because it is passed by value."");" ) ;
774
+ Method cctor = @class . HasNonTrivialCopyConstructor ? @class . Methods . First ( c => c . IsCopyConstructor ) : null ;
775
+ if ( cctor != null && cctor . IsGenerated )
776
+ {
777
+ Context . Before . WriteLine ( $ "if (ReferenceEquals({ Context . Parameter . Name } , null))") ;
778
+ Context . Before . WriteLineIndent (
779
+ $@ "throw new global::System.ArgumentNullException(""{
780
+ Context . Parameter . Name } "", ""Cannot be null because it is passed by value."");" ) ;
778
781
779
- var nativeClass = typePrinter . PrintNative ( @class ) ;
782
+ var nativeClass = typePrinter . PrintNative ( @class ) ;
780
783
781
- var cctorName = CSharpSources . GetFunctionNativeIdentifier ( Context . Context , cctor ) ;
784
+ var cctorName = CSharpSources . GetFunctionNativeIdentifier ( Context . Context , cctor ) ;
782
785
783
- var defaultValue = "" ;
784
- var TypePrinter = new CSharpTypePrinter ( Context . Context ) ;
785
- var ExpressionPrinter = new CSharpExpressionPrinter ( TypePrinter ) ;
786
- if ( cctor . Parameters . Count > 1 )
787
- defaultValue = $ ", { ExpressionPrinter . VisitParameter ( cctor . Parameters . Last ( ) ) } ";
786
+ var defaultValue = "" ;
787
+ var TypePrinter = new CSharpTypePrinter ( Context . Context ) ;
788
+ var ExpressionPrinter = new CSharpExpressionPrinter ( TypePrinter ) ;
789
+ if ( cctor . Parameters . Count > 1 )
790
+ defaultValue = $ ", { ExpressionPrinter . VisitParameter ( cctor . Parameters . Last ( ) ) } ";
788
791
789
- Context . Before . WriteLine ( $ "byte* __{ Context . Parameter . Name } Memory = stackalloc byte[sizeof({ nativeClass } )];") ;
790
- Context . Before . WriteLine ( $ "__IntPtr __{ Context . Parameter . Name } Ptr = (__IntPtr)__{ Context . Parameter . Name } Memory;") ;
791
- Context . Before . WriteLine ( $ "{ nativeClass } .{ cctorName } (__{ Context . Parameter . Name } Ptr, { Context . Parameter . Name } .__Instance{ defaultValue } );") ;
792
- Context . Return . Write ( $ "__{ Context . Parameter . Name } Ptr") ;
792
+ Context . Before . WriteLine ( $ "byte* __{ Context . Parameter . Name } Memory = stackalloc byte[sizeof({ nativeClass } )];") ;
793
+ Context . Before . WriteLine ( $ "__IntPtr __{ Context . Parameter . Name } Ptr = (__IntPtr)__{ Context . Parameter . Name } Memory;") ;
794
+ Context . Before . WriteLine ( $ "{ nativeClass } .{ cctorName } (__{ Context . Parameter . Name } Ptr, { Context . Parameter . Name } .__Instance{ defaultValue } );") ;
795
+ Context . Return . Write ( $ "__{ Context . Parameter . Name } Ptr") ;
793
796
794
- if ( Context . Context . ParserOptions . IsItaniumLikeAbi && @class . HasNonTrivialDestructor )
795
- {
796
- Method dtor = @class . Destructors . FirstOrDefault ( ) ;
797
- if ( dtor != null )
797
+ if ( Context . Context . ParserOptions . IsItaniumLikeAbi && @class . HasNonTrivialDestructor )
798
798
{
799
- // todo: virtual destructors?
800
- Context . Cleanup . WriteLine ( $ "{ nativeClass } .dtor(__{ Context . Parameter . Name } Ptr);") ;
799
+ Method dtor = @class . Destructors . FirstOrDefault ( ) ;
800
+ if ( dtor != null )
801
+ {
802
+ // todo: virtual destructors?
803
+ Context . Cleanup . WriteLine ( $ "{ nativeClass } .dtor(__{ Context . Parameter . Name } Ptr);") ;
804
+ }
801
805
}
802
806
}
807
+ else
808
+ {
809
+ Context . Return . Write ( paramInstance ) ;
810
+ }
803
811
}
812
+ // Non-Kythera classes.
804
813
else
805
814
{
815
+ Context . Before . WriteLine ( $ "if (ReferenceEquals({ Context . Parameter . Name } , null))") ;
816
+ Context . Before . WriteLineIndent (
817
+ $@ "throw new global::System.ArgumentNullException(""{
818
+ Context . Parameter . Name } "", ""Cannot be null because it is passed by value."");" ) ;
806
819
Context . Return . Write ( paramInstance ) ;
807
820
}
808
821
}
0 commit comments