@@ -26,36 +26,67 @@ internal unsafe struct TestStruct
26
26
}
27
27
#pragma warning restore 618
28
28
29
+ [ StructLayout ( LayoutKind . Explicit ) ]
30
+ public class ExplicitBase
31
+ {
32
+ [ FieldOffset ( 8 ) ] public object ? m_objectField ;
33
+ [ FieldOffset ( 0 ) ] public double m_doubleField ;
34
+
35
+ public double DoubleValue
36
+ {
37
+ get => m_doubleField ;
38
+ set => m_doubleField = value ;
39
+ }
40
+ }
41
+
42
+ [ StructLayout ( LayoutKind . Explicit ) ]
43
+ public class EmptyExplicitClassDerivingFromExplicitClass : ExplicitBase
44
+ {
45
+ }
46
+
47
+ public class AutoDerivingFromEmptyExplicitClass : EmptyExplicitClassDerivingFromExplicitClass
48
+ {
49
+ string MyStringField ;
50
+
51
+ public AutoDerivingFromEmptyExplicitClass ( string fieldValue = "Default Value" )
52
+ {
53
+ MyStringField = fieldValue ;
54
+ }
55
+
56
+ public string GetMyStringField ( )
57
+ {
58
+ return MyStringField ;
59
+ }
60
+ }
61
+
29
62
public class Program
30
63
{
31
64
[ Fact ]
32
65
[ OuterLoop ]
33
- public static int TestEntrypoint ( )
66
+ public static void ExplicitLayoutStruct ( )
34
67
{
35
- int returnVal = 100 ;
36
-
37
68
TestStruct t = new TestStruct ( ) ;
38
69
t . Guid1 = Guid . NewGuid ( ) ;
39
70
t . Guid2 = t . Guid1 ;
40
71
41
- if ( t . Guid1 != t . Guid2 )
42
- {
43
- Console . WriteLine ( "FAIL self-copy" ) ;
44
- returnVal = - 1 ;
45
- }
72
+ Assert . Equal ( t . Guid1 , t . Guid2 ) ;
46
73
47
74
TestStruct t2 = new TestStruct ( ) ;
48
75
Guid newGuid = Guid . NewGuid ( ) ;
49
76
t2 . Guid1 = newGuid ;
50
77
t2 . Guid2 = newGuid ;
51
78
52
- if ( t2 . Guid1 != t2 . Guid2 )
53
- {
54
- Console . WriteLine ( "FAIL other-copy" ) ;
55
- returnVal = - 1 ;
56
- }
79
+ Assert . Equal ( t2 . Guid1 , t2 . Guid2 ) ;
80
+ }
81
+
82
+ [ Fact ]
83
+ public static void EmptyExplicitClass ( )
84
+ {
85
+ AutoDerivingFromEmptyExplicitClass emptyDirectBase = new ( "AutoDerivingFromEmptyExplicitClass" ) ;
86
+
87
+ emptyDirectBase . DoubleValue = 17.0 ;
57
88
58
- return returnVal ;
89
+ Assert . Equal ( "AutoDerivingFromEmptyExplicitClass" , emptyDirectBase . GetMyStringField ( ) ) ;
59
90
}
60
91
}
61
92
}
0 commit comments