@@ -896,7 +896,8 @@ private void GenerateFieldSetter(Field field, Class @class, QualifiedType fieldT
896
896
var marshal = new CSharpMarshalManagedToNativePrinter ( ctx ) ;
897
897
ctx . Declaration = field ;
898
898
899
- var arrayType = field . Type . Desugar ( ) as ArrayType ;
899
+ Type type = field . Type . Desugar ( ) ;
900
+ var arrayType = type as ArrayType ;
900
901
901
902
if ( arrayType != null && @class . IsValueType )
902
903
{
@@ -923,13 +924,20 @@ private void GenerateFieldSetter(Field field, Class @class, QualifiedType fieldT
923
924
924
925
if ( marshal . Context . Return . StringBuilder . Length > 0 )
925
926
{
926
- WriteLine ( "{0} = {1}{2};" , ctx . ReturnVarName ,
927
- field . Type . IsPointer ( ) && field . Type . GetFinalPointee ( ) . IsPrimitiveType ( ) &&
928
- ! CSharpTypePrinter . IsConstCharString ( field . Type ) ?
929
- string . Format ( "({0}) " , CSharpTypePrinter . IntPtrType ) :
930
- string . Empty ,
931
- marshal . Context . Return ) ;
932
-
927
+ Write ( $ "{ ctx . ReturnVarName } = ") ;
928
+ if ( type . IsPointer ( ) )
929
+ {
930
+ Type pointee = type . GetFinalPointee ( ) ;
931
+ if ( pointee . IsPrimitiveType ( ) &&
932
+ ! CSharpTypePrinter . IsConstCharString ( type ) )
933
+ {
934
+ Write ( $ "({ CSharpTypePrinter . IntPtrType } ) ") ;
935
+ var templateSubstitution = pointee . Desugar ( false ) as TemplateParameterSubstitutionType ;
936
+ if ( templateSubstitution != null )
937
+ Write ( $ "(object) ") ;
938
+ }
939
+ }
940
+ WriteLine ( $ "{ marshal . Context . Return } ;") ;
933
941
}
934
942
935
943
if ( ( arrayType != null && @class . IsValueType ) || ctx . HasCodeBlock )
@@ -1191,21 +1199,26 @@ private void GenerateFieldGetter(Field field, Class @class, QualifiedType return
1191
1199
if ( ctx . HasCodeBlock )
1192
1200
PushIndent ( ) ;
1193
1201
1202
+ Write ( "return " ) ;
1203
+
1194
1204
var @return = marshal . Context . Return . ToString ( ) ;
1195
1205
if ( field . Type . IsPointer ( ) )
1196
1206
{
1197
- var final = field . Type . GetFinalPointee ( ) . Desugar ( ) ;
1198
- if ( final . IsPrimitiveType ( ) && ! final . IsPrimitiveType ( PrimitiveType . Void ) &&
1207
+ var final = field . Type . GetFinalPointee ( ) . Desugar ( resolveTemplateSubstitution : false ) ;
1208
+ var templateSubstitution = final as TemplateParameterSubstitutionType ;
1209
+ if ( templateSubstitution != null )
1210
+ Write ( $ "({ templateSubstitution . ReplacedParameter . Parameter . Name } ) (object) ") ;
1211
+ if ( ( final . IsPrimitiveType ( ) && ! final . IsPrimitiveType ( PrimitiveType . Void ) &&
1199
1212
( ! final . IsPrimitiveType ( PrimitiveType . Char ) &&
1200
1213
! final . IsPrimitiveType ( PrimitiveType . WideChar ) ||
1201
1214
( ! Context . Options . MarshalCharAsManagedChar &&
1202
- ! ( ( PointerType ) field . Type ) . QualifiedPointee . Qualifiers . IsConst ) ) )
1203
- @return = string . Format ( "({0}*) {1}" , field . Type . GetPointee ( ) . Desugar ( ) , @return ) ;
1204
- if ( ! ( ( PointerType ) field . Type ) . QualifiedPointee . Qualifiers . IsConst &&
1205
- final . IsPrimitiveType ( PrimitiveType . WideChar ) )
1206
- @return = string . Format ( "({0}*) {1}" , field . Type . GetPointee ( ) . Desugar ( ) , @return ) ;
1215
+ ! ( ( PointerType ) field . Type ) . QualifiedPointee . Qualifiers . IsConst ) ) &&
1216
+ templateSubstitution == null ) ||
1217
+ ( ! ( ( PointerType ) field . Type ) . QualifiedPointee . Qualifiers . IsConst &&
1218
+ final . IsPrimitiveType ( PrimitiveType . WideChar ) ) )
1219
+ Write ( $ "({ field . Type . GetPointee ( ) . Desugar ( ) } *) " ) ;
1207
1220
}
1208
- WriteLine ( "return {0 };", @return ) ;
1221
+ WriteLine ( $ " { @return } ;") ;
1209
1222
1210
1223
if ( ( arrayType != null && @class . IsValueType ) || ctx . HasCodeBlock )
1211
1224
WriteCloseBraceIndent ( ) ;
0 commit comments