@@ -820,7 +820,7 @@ private void GenerateVariableSetter(Variable var)
820
820
QualifiedType = var . QualifiedType
821
821
} ;
822
822
823
- var ctx = new CSharpMarshalContext ( Context )
823
+ var ctx = new CSharpMarshalContext ( Context , CurrentIndent )
824
824
{
825
825
Parameter = param ,
826
826
ArgName = param . Name ,
@@ -880,38 +880,40 @@ private void GenerateFunctionSetter(Class @class, Property property)
880
880
881
881
private void GenerateFieldSetter ( Field field , Class @class , QualifiedType fieldType )
882
882
{
883
+ string returnVar ;
884
+ Type type = field . Type . Desugar ( ) ;
885
+ var arrayType = type as ArrayType ;
886
+ if ( arrayType != null && @class . IsValueType )
887
+ {
888
+ returnVar = HandleValueArray ( arrayType , field ) ;
889
+ }
890
+ else
891
+ {
892
+ var name = @class . Layout . Fields . First ( f => f . FieldPtr == field . OriginalPtr ) . Name ;
893
+ var identifier = SafeIdentifier ( name ) ;
894
+ if ( @class . IsValueType )
895
+ returnVar = $ "{ Helpers . InstanceField } .{ identifier } ";
896
+ else
897
+ returnVar = $ "(({ TypePrinter . PrintNative ( @class ) } *){ Helpers . InstanceIdentifier } )->{ identifier } ";
898
+ }
899
+
883
900
var param = new Parameter
884
901
{
885
902
Name = "value" ,
886
903
QualifiedType = field . QualifiedType
887
904
} ;
888
905
889
- var ctx = new CSharpMarshalContext ( Context )
906
+ var ctx = new CSharpMarshalContext ( Context , CurrentIndent )
890
907
{
891
908
Parameter = param ,
892
909
ArgName = param . Name ,
910
+ ReturnVarName = returnVar
893
911
} ;
894
912
ctx . PushMarshalKind ( MarshalKind . NativeField ) ;
895
913
896
914
var marshal = new CSharpMarshalManagedToNativePrinter ( ctx ) ;
897
915
ctx . Declaration = field ;
898
916
899
- Type type = field . Type . Desugar ( ) ;
900
- var arrayType = type as ArrayType ;
901
-
902
- if ( arrayType != null && @class . IsValueType )
903
- {
904
- ctx . ReturnVarName = HandleValueArray ( arrayType , field ) ;
905
- }
906
- else
907
- {
908
- var name = @class . Layout . Fields . First ( f => f . FieldPtr == field . OriginalPtr ) . Name ;
909
- var identifier = SafeIdentifier ( name ) ;
910
- if ( @class . IsValueType )
911
- ctx . ReturnVarName = $ "{ Helpers . InstanceField } .{ identifier } ";
912
- else
913
- ctx . ReturnVarName = $ "(({ TypePrinter . PrintNative ( @class ) } *){ Helpers . InstanceIdentifier } )->{ identifier } ";
914
- }
915
917
param . Visit ( marshal ) ;
916
918
917
919
if ( ! string . IsNullOrWhiteSpace ( marshal . Context . Before ) )
@@ -987,7 +989,7 @@ private void GenerateIndexerSetter(Function function)
987
989
function . OriginalReturnType . Type . IsPointerTo ( out type ) ;
988
990
989
991
var @internal = TypePrinter . PrintNative ( function . Namespace ) ;
990
- var ctx = new CSharpMarshalContext ( Context )
992
+ var ctx = new CSharpMarshalContext ( Context , CurrentIndent )
991
993
{
992
994
Parameter = new Parameter
993
995
{
@@ -1108,7 +1110,7 @@ private void GenerateVariableGetter(Variable var)
1108
1110
1109
1111
TypePrinter . PopContext ( ) ;
1110
1112
1111
- var ctx = new CSharpMarshalContext ( Context )
1113
+ var ctx = new CSharpMarshalContext ( Context , CurrentIndent )
1112
1114
{
1113
1115
ArgName = var . Name ,
1114
1116
ReturnType = new QualifiedType ( var . Type )
@@ -1171,12 +1173,18 @@ private static Property GetActualProperty(Property property, Class c)
1171
1173
private void GenerateFieldGetter ( Field field , Class @class , QualifiedType returnType )
1172
1174
{
1173
1175
var name = @class . Layout . Fields . First ( f => f . FieldPtr == field . OriginalPtr ) . Name ;
1174
- String returnVar ;
1176
+ string returnVar ;
1177
+ var arrayType = field . Type . Desugar ( ) as ArrayType ;
1175
1178
if ( @class . IsValueType )
1176
- returnVar = $@ "{ Helpers . InstanceField } .{ SafeIdentifier ( name ) } ";
1179
+ {
1180
+ if ( arrayType != null )
1181
+ returnVar = HandleValueArray ( arrayType , field ) ;
1182
+ else
1183
+ returnVar = $ "{ Helpers . InstanceField } .{ SafeIdentifier ( name ) } ";
1184
+ }
1177
1185
else
1178
1186
{
1179
- returnVar = $@ "(({ TypePrinter . PrintNative ( @class ) } *) { Helpers . InstanceIdentifier } )->{ SafeIdentifier ( name ) } ";
1187
+ returnVar = $ "(({ TypePrinter . PrintNative ( @class ) } *) { Helpers . InstanceIdentifier } )->{ SafeIdentifier ( name ) } ";
1180
1188
// Class field getter should return a reference object instead of a copy. Wrapping `returnVar` in
1181
1189
// IntPtr ensures that non-copying object constructor is invoked.
1182
1190
Class typeClass ;
@@ -1185,7 +1193,7 @@ private void GenerateFieldGetter(Field field, Class @class, QualifiedType return
1185
1193
returnVar = $ "new { CSharpTypePrinter . IntPtrType } (&{ returnVar } )";
1186
1194
}
1187
1195
1188
- var ctx = new CSharpMarshalContext ( Context )
1196
+ var ctx = new CSharpMarshalContext ( Context , CurrentIndent )
1189
1197
{
1190
1198
ArgName = field . Name ,
1191
1199
Declaration = field ,
@@ -1194,11 +1202,6 @@ private void GenerateFieldGetter(Field field, Class @class, QualifiedType return
1194
1202
} ;
1195
1203
ctx . PushMarshalKind ( MarshalKind . NativeField ) ;
1196
1204
1197
- var arrayType = field . Type . Desugar ( ) as ArrayType ;
1198
-
1199
- if ( arrayType != null && @class . IsValueType )
1200
- ctx . ReturnVarName = HandleValueArray ( arrayType , field ) ;
1201
-
1202
1205
var marshal = new CSharpMarshalNativeToManagedPrinter ( ctx ) ;
1203
1206
field . QualifiedType . Visit ( marshal ) ;
1204
1207
@@ -1666,7 +1669,7 @@ private void GenerateVTableManagedCall(Method method)
1666
1669
if ( param . Kind == ParameterKind . IndirectReturnType )
1667
1670
continue ;
1668
1671
1669
- var ctx = new CSharpMarshalContext ( Context )
1672
+ var ctx = new CSharpMarshalContext ( Context , CurrentIndent )
1670
1673
{
1671
1674
ReturnType = param . QualifiedType ,
1672
1675
ReturnVarName = param . Name ,
@@ -1723,7 +1726,7 @@ private void GenerateVTableManagedCall(Method method)
1723
1726
} ;
1724
1727
1725
1728
// Marshal the managed result to native
1726
- var ctx = new CSharpMarshalContext ( Context )
1729
+ var ctx = new CSharpMarshalContext ( Context , CurrentIndent )
1727
1730
{
1728
1731
ArgName = Helpers . ReturnIdentifier ,
1729
1732
Parameter = param ,
@@ -1901,7 +1904,7 @@ private void GenerateEventRaiseWrapper(Event @event, string delegateInstance)
1901
1904
var returns = new List < string > ( ) ;
1902
1905
foreach ( var param in @event . Parameters )
1903
1906
{
1904
- var ctx = new CSharpMarshalContext ( Context )
1907
+ var ctx = new CSharpMarshalContext ( Context , CurrentIndent )
1905
1908
{
1906
1909
ReturnVarName = param . Name ,
1907
1910
ReturnType = param . QualifiedType
@@ -2853,7 +2856,7 @@ into context
2853
2856
2854
2857
if ( needsReturn )
2855
2858
{
2856
- var ctx = new CSharpMarshalContext ( Context )
2859
+ var ctx = new CSharpMarshalContext ( Context , CurrentIndent )
2857
2860
{
2858
2861
ArgName = Helpers . ReturnIdentifier ,
2859
2862
ReturnVarName = Helpers . ReturnIdentifier ,
@@ -2944,7 +2947,7 @@ private void GenerateFunctionCallOutParams(IEnumerable<ParamMarshal> @params,
2944
2947
2945
2948
var nativeVarName = paramInfo . Name ;
2946
2949
2947
- var ctx = new CSharpMarshalContext ( Context )
2950
+ var ctx = new CSharpMarshalContext ( Context , CurrentIndent )
2948
2951
{
2949
2952
Parameter = param ,
2950
2953
ArgName = nativeVarName ,
@@ -3012,7 +3015,7 @@ private ParamMarshal GenerateFunctionParamMarshal(Parameter param, int paramInde
3012
3015
}
3013
3016
}
3014
3017
3015
- var ctx = new CSharpMarshalContext ( Context )
3018
+ var ctx = new CSharpMarshalContext ( Context , CurrentIndent )
3016
3019
{
3017
3020
Parameter = param ,
3018
3021
ParameterIndex = paramIndex ,
0 commit comments