Add assert when dllmap is disabled and fix support build in netcore mode
[mono-project.git] / mono / tests / field-layout.cs
blob6e32df69896282f00ca987ef4c1c5d5376c2d830
1 using System;
2 using System.Runtime.InteropServices;
4 namespace Test {
5 [StructLayout ( LayoutKind.Explicit )]
6 public struct Doh {
7 [ FieldOffset(0) ] public int a;
8 [ FieldOffset(0) ] public byte a1;
9 [ FieldOffset(1) ] public byte a2;
10 [ FieldOffset(2) ] public byte a3;
11 [ FieldOffset(3) ] public byte a4;
13 [StructLayout ( LayoutKind.Explicit )]
14 public class Doh2 {
15 [ FieldOffset(0) ] public int a;
16 [ FieldOffset(0) ] public byte a1;
17 [ FieldOffset(1) ] public byte a2;
18 [ FieldOffset(2) ] public byte a3;
19 [ FieldOffset(3) ] public byte a4;
21 [StructLayout ( LayoutKind.Explicit )]
22 public class Doh3: Doh2 {
23 [ FieldOffset(0) ] public int b;
25 public class Test {
26 public static int Main() {
27 Doh doh;
28 Doh3 doh2 = new Doh3 ();
29 bool success = false;
30 // shut up the compiler
31 doh.a1 = doh.a2 = doh.a3 = doh.a4 = 0;
32 doh.a = 1;
33 if (doh.a1 == 1 && doh.a2 == 0 && doh.a3 == 0 && doh.a4 == 0) {
34 System.Console.WriteLine ("Little endian");
35 success = true;
36 } else if (doh.a1 == 0 && doh.a2 == 0 && doh.a3 == 0 && doh.a4 == 1) {
37 System.Console.WriteLine ("Big endian");
38 success = true;
40 if (!success)
41 return 1;
42 // shut up the compiler
43 doh2.a1 = doh2.a2 = doh2.a3 = doh2.a4 = 0;
44 doh2.a = 1;
45 if (doh2.a1 == 1 && doh2.a2 == 0 && doh2.a3 == 0 && doh2.a4 == 0) {
46 success = true;
47 } else if (doh2.a1 == 0 && doh2.a2 == 0 && doh2.a3 == 0 && doh2.a4 == 1) {
48 success = true;
50 doh2.b = 3;
51 if (doh2.a != 3)
52 success = false;
53 if (!success)
54 return 1;
55 return 0;