Add PInvoke/Array tests (#19266)
[platform/upstream/coreclr.git] / tests / src / Interop / PInvoke / Array / MarshalArrayAsField / AsByValArray / FldDef_DefaultArray.cs
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5 using System;
6 using System.Runtime.InteropServices;
7
8 #pragma warning disable 618
9
10 #region Struct Definition
11 [StructLayout(LayoutKind.Sequential)]
12 public struct S2
13 {
14     public int i32;
15     public uint ui32;
16     public short s1;
17     public ushort us1;
18     public Byte b;
19     public SByte sb;
20     public Int16 i16;
21     public UInt16 ui16;
22     public Int64 i64;
23     public UInt64 ui64;
24     public Single sgl;
25     public Double d;
26 }
27
28 [StructLayout(LayoutKind.Sequential)]
29 public struct Struct_Sequential
30 {
31     public int[] longArr;
32
33     public uint[] ulongArr;
34
35     public short[] shortArr;
36
37     public ushort[] ushortArr;
38
39     public long[] long64Arr;
40
41     public ulong[] ulong64Arr;
42
43     public double[] doubleArr;
44
45     public float[] floatArr;
46
47     public byte[] byteArr;
48
49     //not default
50     //helper field definition, just match structure member verification func on C++ side
51     [MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BSTR)]
52     public string[] bstrArr;
53
54     public bool[] boolArr;
55 }
56
57 [StructLayout(LayoutKind.Explicit)]
58 public struct Struct_Explicit
59 {
60     [FieldOffset(0 * 8)]
61     public int[] longArr;
62
63     [FieldOffset(1 * 8)]
64     public uint[] ulongArr;
65
66     [FieldOffset(2 * 8)]
67     public short[] shortArr;
68
69     [FieldOffset(3 * 8)]
70     public ushort[] ushortArr;
71
72     [FieldOffset(4 * 8)]
73     public long[] long64Arr;
74
75     [FieldOffset(5 * 8)]
76     public ulong[] ulong64Arr;
77
78     [FieldOffset(6 * 8)]
79     public double[] doubleArr;
80
81     [FieldOffset(7 * 8)]
82     public float[] floatArr;
83
84     [FieldOffset(8 * 8)]
85     public byte[] byteArr;
86
87     [FieldOffset(9 * 8)]
88     [MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BSTR)]
89     public string[] bstrArr;
90
91     [FieldOffset(10 * 8)]
92     public bool[] boolArr;
93 }
94
95 [StructLayout(LayoutKind.Sequential)]
96 public struct Struct_SeqWithArrOfStr
97 {
98     public S2[] arrS2;
99 }
100
101 [StructLayout(LayoutKind.Explicit)]
102 public struct Struct_ExpWithArrOfStr
103 {
104     [FieldOffset(0)]
105     public S2[] arrS2;
106 }
107 #endregion
108
109 #region Class Definition
110 [StructLayout(LayoutKind.Sequential)]
111 public class Class_Sequential
112 {
113     public int[] longArr;
114
115     public uint[] ulongArr;
116
117     public short[] shortArr;
118
119     public ushort[] ushortArr;
120
121     public long[] long64Arr;
122
123     public ulong[] ulong64Arr;
124
125     public double[] doubleArr;
126
127     public float[] floatArr;
128
129     public byte[] byteArr;
130
131     [MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BSTR)]
132     public string[] bstrArr;
133
134     public bool[] boolArr;
135 }
136
137 [StructLayout(LayoutKind.Explicit)]
138 public class Class_Explicit
139 {
140     [FieldOffset(0 * 8)]
141     public int[] longArr;
142
143     [FieldOffset(1 * 8)]
144     public uint[] ulongArr;
145
146     [FieldOffset(2 * 8)]
147     public short[] shortArr;
148
149     [FieldOffset(3 * 8)]
150     public ushort[] ushortArr;
151
152     [FieldOffset(4 * 8)]
153     public long[] long64Arr;
154
155     [FieldOffset(5 * 8)]
156     public ulong[] ulong64Arr;
157
158     [FieldOffset(6 * 8)]
159     public double[] doubleArr;
160
161     [FieldOffset(7 * 8)]
162     public float[] floatArr;
163
164     [FieldOffset(8 * 8)]
165     public byte[] byteArr;
166
167     [FieldOffset(9 * 8)]
168     [MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BSTR)]
169     public string[] bstrArr;
170
171     [FieldOffset(10 * 8)]
172     public bool[] boolArr;
173 }
174
175 [StructLayout(LayoutKind.Sequential)]
176 public class Class_SeqWithArrOfStr
177 {
178     public S2[] arrS2;
179 }
180
181 [StructLayout(LayoutKind.Explicit)]
182 public class Class_ExpWithArrOfStr
183 {
184     [FieldOffset(0)]
185     public S2[] arrS2;
186 }
187 #endregion
188
189 #pragma warning restore 618