@@ -305,7 +305,7 @@ public void WriteClassInstance(Class @class, string instance, bool ownNativeInst
305
305
Context . Return . Write ( "({0} == nullptr) ? nullptr : gcnew " ,
306
306
instance ) ;
307
307
308
- Context . Return . Write ( "{0}(" , QualifiedIdentifier ( @class ) ) ;
308
+ Context . Return . Write ( ":: {0}(" , QualifiedIdentifier ( @class ) ) ;
309
309
Context . Return . Write ( "(::{0}*)" , @class . QualifiedOriginalName ) ;
310
310
Context . Return . Write ( "{0}{1})" , instance , ownNativeInstance ? ", true" : "" ) ;
311
311
}
@@ -433,39 +433,42 @@ public override bool VisitArrayType(ArrayType array, TypeQualifiers quals)
433
433
case ArrayType . ArraySize . Constant :
434
434
if ( string . IsNullOrEmpty ( Context . ReturnVarName ) )
435
435
{
436
- const string pinnedPtr = "__pinnedPtr ";
437
- Context . Before . WriteLine ( "cli::pin_ptr<{0}> {1} = &{2}[0 ];",
438
- array . Type , pinnedPtr , Context . Parameter . Name ) ;
439
- const string arrayPtr = "__arrayPtr" ;
440
- Context . Before . WriteLine ( "{0}* {1} = {2};" , array . Type , arrayPtr , pinnedPtr ) ;
441
- Context . Return . Write ( "({0} (&)[{1}]) {2}" , array . Type , array . Size , arrayPtr ) ;
436
+ string arrayPtrRet = $ "__ { Context . ParameterIndex } ArrayPtr ";
437
+ Context . Before . WriteLine ( $ " { array . Type } { arrayPtrRet } [ { array . Size } ];") ;
438
+
439
+ Context . ReturnVarName = arrayPtrRet ;
440
+
441
+ Context . Return . Write ( arrayPtrRet ) ;
442
442
}
443
- else
443
+
444
+ bool isPointerToPrimitive = array . Type . IsPointerToPrimitiveType ( PrimitiveType . Void ) ;
445
+ bool isPrimitive = array . Type . IsPrimitiveType ( ) ;
446
+ var supportBefore = Context . Before ;
447
+ supportBefore . WriteLine ( "if ({0} != nullptr)" , Context . Parameter . Name ) ;
448
+ supportBefore . WriteOpenBraceAndIndent ( ) ;
449
+
450
+ supportBefore . WriteLine ( $ "if ({ Context . Parameter . Name } ->Length != { array . Size } )") ;
451
+ supportBefore . WriteOpenBraceAndIndent ( ) ;
452
+ supportBefore . WriteLine ( $ "throw gcnew System::InvalidOperationException(\" Source array size must equal destination array size.\" );") ;
453
+ supportBefore . UnindentAndWriteCloseBrace ( ) ;
454
+
455
+ string nativeVal = string . Empty ;
456
+ if ( isPointerToPrimitive )
457
+ {
458
+ nativeVal = ".ToPointer()" ;
459
+ }
460
+ else if ( ! isPrimitive )
444
461
{
445
- bool isPointerToPrimitive = array . Type . IsPointerToPrimitiveType ( PrimitiveType . Void ) ;
446
- bool isPrimitive = array . Type . IsPrimitiveType ( ) ;
447
- var supportBefore = Context . Before ;
448
- supportBefore . WriteLine ( "if ({0} != nullptr)" , Context . ArgName ) ;
449
- supportBefore . WriteOpenBraceAndIndent ( ) ;
450
-
451
- string nativeVal = string . Empty ;
452
- if ( isPointerToPrimitive )
453
- {
454
- nativeVal = ".ToPointer()" ;
455
- }
456
- else if ( ! isPrimitive )
457
- {
458
- nativeVal = "->NativePtr" ;
459
- }
460
-
461
- supportBefore . WriteLine ( "for (int i = 0; i < {0}; i++)" , array . Size ) ;
462
- supportBefore . WriteLineIndent ( "{0}[i] = {1}{2}[i]{3};" ,
463
- Context . ReturnVarName ,
464
- isPointerToPrimitive || isPrimitive ? string . Empty : "*" ,
465
- Context . ArgName ,
466
- nativeVal ) ;
467
- supportBefore . UnindentAndWriteCloseBrace ( ) ;
462
+ nativeVal = "->NativePtr" ;
468
463
}
464
+
465
+ supportBefore . WriteLine ( "for (int i = 0; i < {0}; i++)" , array . Size ) ;
466
+ supportBefore . WriteLineIndent ( "{0}[i] = {1}{2}[i]{3};" ,
467
+ Context . ReturnVarName ,
468
+ isPointerToPrimitive || isPrimitive ? string . Empty : "*" ,
469
+ Context . Parameter . Name ,
470
+ nativeVal ) ;
471
+ supportBefore . UnindentAndWriteCloseBrace ( ) ;
469
472
break ;
470
473
default :
471
474
Context . Return . Write ( "null" ) ;
@@ -778,7 +781,8 @@ private void MarshalValueClassProperty(Property property, string marshalVar)
778
781
{
779
782
ArgName = fieldRef ,
780
783
ParameterIndex = Context . ParameterIndex ++ ,
781
- MarshalVarPrefix = Context . MarshalVarPrefix
784
+ MarshalVarPrefix = Context . MarshalVarPrefix ,
785
+ ReturnVarName = $ "{ marshalVar } .{ property . Field . OriginalName } "
782
786
} ;
783
787
784
788
var marshal = new CLIMarshalManagedToNativePrinter ( marshalCtx ) ;
@@ -789,23 +793,26 @@ private void MarshalValueClassProperty(Property property, string marshalVar)
789
793
if ( ! string . IsNullOrWhiteSpace ( marshal . Context . Before ) )
790
794
Context . Before . Write ( marshal . Context . Before ) ;
791
795
792
- Type type ;
793
- Class @class ;
794
- var isRef = property . Type . IsPointerTo ( out type ) &&
795
- ! ( type . TryGetClass ( out @class ) && @class . IsValueType ) &&
796
- ! type . IsPrimitiveType ( ) ;
797
-
798
- if ( isRef )
796
+ if ( ! string . IsNullOrWhiteSpace ( marshal . Context . Return ) )
799
797
{
800
- Context . Before . WriteLine ( "if ({0} != nullptr)" , fieldRef ) ;
801
- Context . Before . Indent ( ) ;
802
- }
798
+ Type type ;
799
+ Class @class ;
800
+ var isRef = property . Type . IsPointerTo ( out type ) &&
801
+ ! ( type . TryGetClass ( out @class ) && @class . IsValueType ) &&
802
+ ! type . IsPrimitiveType ( ) ;
803
803
804
- Context . Before . WriteLine ( "{0}.{1} = {2};" , marshalVar ,
805
- property . Field . OriginalName , marshal . Context . Return ) ;
804
+ if ( isRef )
805
+ {
806
+ Context . Before . WriteLine ( "if ({0} != nullptr)" , fieldRef ) ;
807
+ Context . Before . Indent ( ) ;
808
+ }
806
809
807
- if ( isRef )
808
- Context . Before . Unindent ( ) ;
810
+ Context . Before . WriteLine ( "{0}.{1} = {2};" , marshalVar ,
811
+ property . Field . OriginalName , marshal . Context . Return ) ;
812
+
813
+ if ( isRef )
814
+ Context . Before . Unindent ( ) ;
815
+ }
809
816
}
810
817
811
818
public override bool VisitFieldDecl ( Field field )
0 commit comments