@@ -123,6 +123,8 @@ public struct RecursiveTestStruct
123
123
124
124
class StructureTests
125
125
{
126
+ private const string SimpleBlittableSeqLayoutClass_UpdateField = nameof ( SimpleBlittableSeqLayoutClass_UpdateField ) ;
127
+
126
128
[ DllImport ( "LayoutClassNative" ) ]
127
129
private static extern bool SimpleSeqLayoutClassByRef ( SeqClass p ) ;
128
130
@@ -132,17 +134,23 @@ class StructureTests
132
134
[ DllImport ( "LayoutClassNative" ) ]
133
135
private static extern bool SimpleExpLayoutClassByRef ( ExpClass p ) ;
134
136
135
- [ DllImport ( "LayoutClassNative" ) ]
137
+ [ DllImport ( "LayoutClassNative" , EntryPoint = SimpleBlittableSeqLayoutClass_UpdateField ) ]
136
138
private static extern bool SimpleBlittableSeqLayoutClassByRef ( Blittable p ) ;
137
139
138
- [ DllImport ( "LayoutClassNative" ) ]
140
+ [ DllImport ( "LayoutClassNative" , EntryPoint = SimpleBlittableSeqLayoutClass_UpdateField ) ]
141
+ private static extern bool SimpleBlittableSeqLayoutClassByInAttr ( [ In ] Blittable p ) ;
142
+
143
+ [ DllImport ( "LayoutClassNative" , EntryPoint = SimpleBlittableSeqLayoutClass_UpdateField ) ]
139
144
private static extern bool SimpleBlittableSeqLayoutClassByOutAttr ( [ Out ] Blittable p ) ;
140
145
141
- [ DllImport ( "LayoutClassNative" ) ]
142
- private static extern bool SimpleBlittableSeqLayoutClassByRef ( SealedBlittable p ) ;
146
+ [ DllImport ( "LayoutClassNative" , EntryPoint = SimpleBlittableSeqLayoutClass_UpdateField ) ]
147
+ private static extern bool SealedBlittableSeqLayoutClassByRef ( SealedBlittable p ) ;
143
148
144
- [ DllImport ( "LayoutClassNative" ) ]
145
- private static extern bool SimpleBlittableSeqLayoutClassByOutAttr ( [ Out ] SealedBlittable p ) ;
149
+ [ DllImport ( "LayoutClassNative" , EntryPoint = SimpleBlittableSeqLayoutClass_UpdateField ) ]
150
+ private static extern bool SealedBlittableSeqLayoutClassByInAttr ( [ In ] SealedBlittable p ) ;
151
+
152
+ [ DllImport ( "LayoutClassNative" , EntryPoint = SimpleBlittableSeqLayoutClass_UpdateField ) ]
153
+ private static extern bool SealedBlittableSeqLayoutClassByOutAttr ( [ Out ] SealedBlittable p ) ;
146
154
147
155
[ DllImport ( "LayoutClassNative" ) ]
148
156
private static extern bool SimpleNestedLayoutClassByValue ( NestedLayout p ) ;
@@ -176,42 +184,64 @@ public static void ExplicitClass()
176
184
Assert . IsTrue ( SimpleExpLayoutClassByRef ( p ) ) ;
177
185
}
178
186
187
+ private static void ValidateBlittableClassInOut ( Func < Blittable , bool > pinvoke )
188
+ {
189
+ int a = 10 ;
190
+ int expected = a + 1 ;
191
+ Blittable p = new Blittable ( a ) ;
192
+ Assert . IsTrue ( pinvoke ( p ) ) ;
193
+ Assert . AreEqual ( expected , p . a ) ;
194
+ }
195
+
179
196
public static void BlittableClass ( )
180
197
{
198
+ // [Compat] Marshalled with [In, Out] behaviour by default
181
199
Console . WriteLine ( $ "Running { nameof ( BlittableClass ) } ...") ;
200
+ ValidateBlittableClassInOut ( SimpleBlittableSeqLayoutClassByRef ) ;
201
+ }
182
202
183
- Blittable p = new Blittable ( 10 ) ;
184
- Assert . IsTrue ( SimpleBlittableSeqLayoutClassByRef ( p ) ) ;
203
+ public static void BlittableClassByInAttr ( )
204
+ {
205
+ // [Compat] Marshalled with [In, Out] behaviour even when only [In] is specified
206
+ Console . WriteLine ( $ "Running { nameof ( BlittableClassByInAttr ) } ...") ;
207
+ ValidateBlittableClassInOut ( SimpleBlittableSeqLayoutClassByInAttr ) ;
185
208
}
186
209
187
210
public static void BlittableClassByOutAttr ( )
188
211
{
212
+ // [Compat] Marshalled with [In, Out] behaviour even when only [Out] is specified
189
213
Console . WriteLine ( $ "Running { nameof ( BlittableClassByOutAttr ) } ...") ;
214
+ ValidateBlittableClassInOut ( SimpleBlittableSeqLayoutClassByOutAttr ) ;
215
+ }
190
216
217
+ private static void ValidateSealedBlittableClassInOut ( Func < SealedBlittable , bool > pinvoke )
218
+ {
191
219
int a = 10 ;
192
220
int expected = a + 1 ;
193
- Blittable p = new Blittable ( a ) ;
194
- Assert . IsTrue ( SimpleBlittableSeqLayoutClassByOutAttr ( p ) ) ;
221
+ SealedBlittable p = new SealedBlittable ( a ) ;
222
+ Assert . IsTrue ( pinvoke ( p ) ) ;
195
223
Assert . AreEqual ( expected , p . a ) ;
196
224
}
197
225
198
226
public static void SealedBlittableClass ( )
199
227
{
228
+ // [Compat] Marshalled with [In, Out] behaviour by default
200
229
Console . WriteLine ( $ "Running { nameof ( SealedBlittableClass ) } ...") ;
230
+ ValidateSealedBlittableClassInOut ( SealedBlittableSeqLayoutClassByRef ) ;
231
+ }
201
232
202
- SealedBlittable p = new SealedBlittable ( 10 ) ;
203
- Assert . IsTrue ( SimpleBlittableSeqLayoutClassByRef ( p ) ) ;
233
+ public static void SealedBlittableClassByInAttr ( )
234
+ {
235
+ // [Compat] Marshalled with [In, Out] behaviour even when only [In] is specified
236
+ Console . WriteLine ( $ "Running { nameof ( SealedBlittableClassByOutAttr ) } ...") ;
237
+ ValidateSealedBlittableClassInOut ( SealedBlittableSeqLayoutClassByInAttr ) ;
204
238
}
205
239
206
240
public static void SealedBlittableClassByOutAttr ( )
207
241
{
242
+ // [Compat] Marshalled with [In, Out] behaviour even when only [Out] is specified
208
243
Console . WriteLine ( $ "Running { nameof ( SealedBlittableClassByOutAttr ) } ...") ;
209
-
210
- int a = 10 ;
211
- int expected = a + 1 ;
212
- SealedBlittable p = new SealedBlittable ( a ) ;
213
- Assert . IsTrue ( SimpleBlittableSeqLayoutClassByOutAttr ( p ) ) ;
214
- Assert . AreEqual ( expected , p . a ) ;
244
+ ValidateSealedBlittableClassInOut ( SealedBlittableSeqLayoutClassByOutAttr ) ;
215
245
}
216
246
217
247
public static void NestedLayoutClass ( )
@@ -243,6 +273,8 @@ public static int Main(string[] argv)
243
273
ExplicitClass ( ) ;
244
274
BlittableClass ( ) ;
245
275
SealedBlittableClass ( ) ;
276
+ BlittableClassByInAttr ( ) ;
277
+ SealedBlittableClassByInAttr ( ) ;
246
278
BlittableClassByOutAttr ( ) ;
247
279
SealedBlittableClassByOutAttr ( ) ;
248
280
NestedLayoutClass ( ) ;
0 commit comments