[System.Net] Add support for .pac proxy config scripts on mac
[mono.git] / mcs / class / corlib / Test / System.Reflection / FieldInfoTest.cs
1 //
2 // FieldInfoTest - NUnit Test Cases for the FieldInfo class
3 //
4 // Authors:
5 //      Zoltan Varga (vargaz@freemail.hu)
6 //      Gert Driesen (drieseng@users.sourceforge.net)
7 //
8 // (c) 2003 Ximian, Inc. (http://www.ximian.com)
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System;
32 using System.Threading;
33 using System.Reflection;
34 #if !TARGET_JVM && !MONOTOUCH
35 using System.Reflection.Emit;
36 #endif // TARGET_JVM
37 using System.Runtime.InteropServices;
38
39 using NUnit.Framework;
40
41 namespace MonoTests.System.Reflection
42 {
43         [StructLayout(LayoutKind.Explicit, Pack = 4, Size = 64)]
44         public class Class1
45         {
46                 [FieldOffset (32)]
47                 public int i;
48         }
49
50         [StructLayout(LayoutKind.Sequential)]
51         public class Class2
52         {
53                 [MarshalAsAttribute(UnmanagedType.Bool)]
54                 public int f0;
55
56                 [MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)]
57                 public string[] f1;
58
59                 [MarshalAs(UnmanagedType.ByValTStr, SizeConst=100)]
60                 public string f2;
61
62                 [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof (Marshal1), MarshalCookie="5")]
63                 public int f3;
64
65                 [MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof (Marshal1), MarshalCookie = "5")]
66                 public object f4;
67
68                 [Obsolete]
69                 public int f5;
70         }
71
72         public class Class3 : Class2
73         {
74         }
75
76         class FieldInvokeMatrix
77         {
78                 public Byte field_Byte;
79                 public SByte field_SByte;
80                 public Boolean field_Boolean;
81                 public Char field_Char;
82                 public Int16 field_Int16;
83                 public UInt16 field_UInt16;
84                 public Int32 field_Int32;
85                 public UInt32 field_UInt32;
86                 public Int64 field_Int64;
87                 public UInt64 field_UInt64;
88                 public Single field_Single;
89                 public Double field_Double;
90                 public IntPtr field_IntPtr;
91                 public UIntPtr field_UIntPtr;
92                 public Decimal field_Decimal;
93                 public DateTime field_DateTime;
94                 public String field_String;
95
96                 public ByteEnum field_ByteEnum;
97                 public SByteEnum field_SByteEnum;
98                 public Int16Enum field_Int16Enum;
99                 public UInt16Enum field_UInt16Enum;
100                 public Int32Enum field_Int32Enum;
101                 public UInt32Enum field_UInt32Enum;
102                 public Int64Enum field_Int64Enum;
103                 public UInt64Enum field_UInt64Enum;
104         }
105
106         public enum ByteEnum : byte
107         {
108                 MaxValue = Byte.MaxValue
109         }
110
111         public enum SByteEnum : sbyte
112         {
113                 MaxValue = SByte.MaxValue
114         }
115
116         public enum Int16Enum : short
117         {
118                 MaxValue = Int16.MaxValue
119         }
120
121         public enum UInt16Enum : ushort
122         {
123                 MaxValue = UInt16.MaxValue
124         }
125
126         public enum Int32Enum : int
127         {
128                 MaxValue = Int32.MaxValue
129         }
130
131         public enum UInt32Enum: uint
132         {
133                 MaxValue= UInt32.MaxValue
134         }
135
136         public enum Int64Enum : long
137         {
138                 MaxValue = Int64.MaxValue
139         }
140
141         public enum UInt64Enum: ulong
142         {
143                 MaxValue = UInt64.MaxValue
144         }
145
146         [TestFixture]
147         public unsafe class FieldInfoTest
148         {
149                 [NonSerialized]
150                 public int i;
151
152                 [Test]
153                 public void IsDefined_AttributeType_Null ()
154                 {
155                         Type type = typeof (FieldInfoTest);
156                         FieldInfo field = type.GetField ("i");
157
158                         try {
159                                 field.IsDefined ((Type) null, false);
160                                 Assert.Fail ("#1");
161                         } catch (ArgumentNullException ex) {
162                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
163                                 Assert.IsNull (ex.InnerException, "#3");
164                                 Assert.IsNotNull (ex.Message, "#4");
165                                 Assert.IsNotNull (ex.ParamName, "#5");
166                                 Assert.AreEqual ("attributeType", ex.ParamName, "#6");
167                         }
168                 }
169
170                 [Test]
171                 public void GetCustomAttributes ()
172                 {
173                         object [] attrs;
174                         FieldInfo fi;
175
176                         fi = typeof (Class2).GetField ("f5");
177
178                         attrs = fi.GetCustomAttributes (false);
179                         Assert.AreEqual (1, attrs.Length, "#B1");
180                         Assert.AreEqual (typeof (ObsoleteAttribute), attrs [0].GetType (), "#B2");
181                         attrs = fi.GetCustomAttributes (true);
182                         Assert.AreEqual (1, attrs.Length, "#B3");
183                         Assert.AreEqual (typeof (ObsoleteAttribute), attrs [0].GetType (), "#B4");
184                         attrs = fi.GetCustomAttributes (typeof (MarshalAsAttribute), false);
185                         Assert.AreEqual (0, attrs.Length, "#B5");
186                         attrs = fi.GetCustomAttributes (typeof (MarshalAsAttribute), true);
187                         Assert.AreEqual (0, attrs.Length, "#B6");
188                         attrs = fi.GetCustomAttributes (typeof (ObsoleteAttribute), false);
189                         Assert.AreEqual (1, attrs.Length, "#B7");
190                         Assert.AreEqual (typeof (ObsoleteAttribute), attrs [0].GetType (), "#B8");
191                         attrs = fi.GetCustomAttributes (typeof (ObsoleteAttribute), true);
192                         Assert.AreEqual (1, attrs.Length, "#B9");
193                         Assert.AreEqual (typeof (ObsoleteAttribute), attrs [0].GetType (), "#B10");
194
195                         fi = typeof (Class3).GetField ("f5");
196
197                         attrs = fi.GetCustomAttributes (false);
198                         Assert.AreEqual (1, attrs.Length, "#D1");
199                         Assert.AreEqual (typeof (ObsoleteAttribute), attrs [0].GetType (), "#D2");
200                         attrs = fi.GetCustomAttributes (true);
201                         Assert.AreEqual (1, attrs.Length, "#D3");
202                         Assert.AreEqual (typeof (ObsoleteAttribute), attrs [0].GetType (), "#D4");
203                         attrs = fi.GetCustomAttributes (typeof (MarshalAsAttribute), false);
204                         Assert.AreEqual (0, attrs.Length, "#D5");
205                         attrs = fi.GetCustomAttributes (typeof (MarshalAsAttribute), true);
206                         Assert.AreEqual (0, attrs.Length, "#D6");
207                         attrs = fi.GetCustomAttributes (typeof (ObsoleteAttribute), false);
208                         Assert.AreEqual (1, attrs.Length, "#D7");
209                         Assert.AreEqual (typeof (ObsoleteAttribute), attrs [0].GetType (), "#D8");
210                         attrs = fi.GetCustomAttributes (typeof (ObsoleteAttribute), true);
211                         Assert.AreEqual (1, attrs.Length, "#D9");
212                         Assert.AreEqual (typeof (ObsoleteAttribute), attrs [0].GetType (), "#D10");
213                 }
214
215                 [Test] // GetFieldFromHandle (RuntimeFieldHandle)
216                 public void GetFieldFromHandle1_Handle_Zero ()
217                 {
218                         RuntimeFieldHandle fh = new RuntimeFieldHandle ();
219
220                         try {
221                                 FieldInfo.GetFieldFromHandle (fh);
222                                 Assert.Fail ("#1");
223                         } catch (ArgumentException ex) {
224                                 // Handle is not initialized
225                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
226                                 Assert.IsNull (ex.InnerException, "#3");
227                                 Assert.IsNotNull (ex.Message, "#4");
228                                 Assert.IsNull (ex.ParamName, "#5");
229                         }
230                 }
231
232 #if NET_2_0
233                 [Test] // GetFieldFromHandle (RuntimeFieldHandle, RuntimeTypeHandle)
234                 public void GetFieldFromHandle2_DeclaringType_Zero ()
235                 {
236                         RuntimeTypeHandle th = new RuntimeTypeHandle ();
237                         FieldInfo fi1 = typeof (Class2).GetField ("f5");
238                         RuntimeFieldHandle fh = fi1.FieldHandle;
239
240                         FieldInfo fi2 = FieldInfo.GetFieldFromHandle (fh, th);
241                         Assert.IsNotNull (fi2, "#1");
242                         Assert.AreSame (fi1.DeclaringType, fi2.DeclaringType, "#2");
243                         Assert.AreEqual (fi1.FieldType, fi2.FieldType, "#3");
244                         Assert.AreEqual (fi1.Name, fi2.Name, "#4");
245                 }
246
247                 [Test] // GetFieldFromHandle (RuntimeFieldHandle, RuntimeTypeHandle)
248                 public void GetFieldFromHandle2_Handle_Generic ()
249                 {
250                         FieldInfoTest<string> instance = new FieldInfoTest<string> ();
251                         Type t = instance.GetType ();
252
253                         FieldInfo fi1 = t.GetField ("TestField");
254                         RuntimeFieldHandle fh = fi1.FieldHandle;
255                         RuntimeTypeHandle th = t.TypeHandle;
256
257                         FieldInfo fi2 = FieldInfo.GetFieldFromHandle (fh, th);
258                         Assert.IsNotNull (fi2, "#1");
259                         Assert.AreSame (t, fi2.DeclaringType, "#2");
260                         Assert.AreEqual (typeof (string), fi2.FieldType, "#3");
261                         Assert.AreEqual ("TestField", fi2.Name, "#4");
262                 }
263
264                 [Test] // GetFieldFromHandle (RuntimeFieldHandle, RuntimeTypeHandle)
265                 [Category ("NotWorking")]
266                 [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=343449
267                 public void GetFieldFromHandle2_Handle_GenericDefinition ()
268                 {
269                         Type t1 = typeof (FieldInfoTest<>);
270                         FieldInfo fi1 = t1.GetField ("TestField");
271                         RuntimeFieldHandle fh = fi1.FieldHandle;
272
273                         FieldInfoTest<string> instance = new FieldInfoTest<string> ();
274                         Type t2 = instance.GetType ();
275                         RuntimeTypeHandle th = t2.TypeHandle;
276
277                         FieldInfo fi2 = FieldInfo.GetFieldFromHandle (fh, th);
278                         Assert.IsNotNull (fi2, "#1");
279                         Assert.AreSame (t2, fi2.DeclaringType, "#2");
280                         Assert.AreEqual (typeof (string), fi2.FieldType, "#3");
281                         Assert.AreEqual ("TestField", fi2.Name, "#4");
282                 }
283
284                 [Test] // GetFieldFromHandle (RuntimeFieldHandle, RuntimeTypeHandle)
285                 public void GetFieldFromHandle2_Handle_Zero ()
286                 {
287                         object instance = new Class2 ();
288                         RuntimeTypeHandle th = Type.GetTypeHandle (instance);
289                         RuntimeFieldHandle fh = new RuntimeFieldHandle ();
290
291                         try {
292                                 FieldInfo.GetFieldFromHandle (fh, th);
293                                 Assert.Fail ("#1");
294                         } catch (ArgumentException ex) {
295                                 // Handle is not initialized
296                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
297                                 Assert.IsNull (ex.InnerException, "#3");
298                                 Assert.IsNotNull (ex.Message, "#4");
299                                 Assert.IsNull (ex.ParamName, "#5");
300                         }
301                 }
302
303                 [Test]
304                 [ExpectedException (typeof (ArgumentException))]
305                 public void GetFieldFromHandle2_Incompatible ()
306                 {
307                         RuntimeFieldHandle fh = typeof (FieldInfoTest<int>).GetField ("TestField").FieldHandle;
308
309                         FieldInfoTest<string> instance = new FieldInfoTest<string> ();
310                         Type t2 = instance.GetType ();
311                         RuntimeTypeHandle th = t2.TypeHandle;
312
313                         FieldInfo fi2 = FieldInfo.GetFieldFromHandle (fh, th);
314                 }
315 #endif
316
317                 [Test]
318                 public void PseudoCustomAttributes ()
319                 {
320                         object [] attrs;
321                         Type t = typeof (FieldInfoTest);
322
323                         Assert.AreEqual (1, t.GetField ("i").GetCustomAttributes (typeof (NonSerializedAttribute), true).Length);
324
325                         attrs = typeof (Class1).GetField ("i").GetCustomAttributes (true);
326                         Assert.AreEqual (1, attrs.Length, "#B1");
327                         FieldOffsetAttribute field_attr = (FieldOffsetAttribute) attrs [0];
328                         Assert.AreEqual (32, field_attr.Value, "#B2");
329
330                         MarshalAsAttribute attr;
331
332                         attrs = typeof (Class2).GetField ("f0").GetCustomAttributes (true);
333                         Assert.AreEqual (1, attrs.Length, "#C1");
334                         attr = (MarshalAsAttribute) attrs [0];
335                         Assert.AreEqual (UnmanagedType.Bool, attr.Value, "#C2");
336
337                         attrs = typeof (Class2).GetField ("f1").GetCustomAttributes (true);
338                         Assert.AreEqual (1, attrs.Length, "#D1");
339                         attr = (MarshalAsAttribute) attrs [0];
340                         Assert.AreEqual (UnmanagedType.LPArray, attr.Value, "#D2");
341                         Assert.AreEqual (UnmanagedType.LPStr, attr.ArraySubType, "#D3");
342
343                         attrs = typeof (Class2).GetField ("f2").GetCustomAttributes (true);
344                         Assert.AreEqual (1, attrs.Length, "#E1");
345                         attr = (MarshalAsAttribute) attrs [0];
346                         Assert.AreEqual (UnmanagedType.ByValTStr, attr.Value, "#E2");
347                         Assert.AreEqual (100, attr.SizeConst, "#E3");
348
349                         attrs = typeof (Class2).GetField ("f3").GetCustomAttributes (true);
350                         Assert.AreEqual (1, attrs.Length, "#F1");
351                         attr = (MarshalAsAttribute) attrs [0];
352                         Assert.AreEqual (UnmanagedType.CustomMarshaler, attr.Value, "#F2");
353                         Assert.AreEqual ("5", attr.MarshalCookie, "#F3");
354                         Assert.AreEqual (typeof (Marshal1), Type.GetType (attr.MarshalType), "#F4");
355
356                         attrs = typeof (Class3).GetField ("f3").GetCustomAttributes (false);
357                         Assert.AreEqual (1, attrs.Length, "#G1");
358                         attr = (MarshalAsAttribute) attrs [0];
359                         Assert.AreEqual (UnmanagedType.CustomMarshaler, attr.Value, "#G2");
360                         Assert.AreEqual ("5", attr.MarshalCookie, "#G3");
361                         Assert.AreEqual (typeof (Marshal1), Type.GetType (attr.MarshalType), "#G4");
362
363                         attrs = typeof (Class3).GetField ("f3").GetCustomAttributes (true);
364                         Assert.AreEqual (1, attrs.Length, "#H1");
365                         attr = (MarshalAsAttribute) attrs [0];
366                         Assert.AreEqual (UnmanagedType.CustomMarshaler, attr.Value, "#H2");
367                         Assert.AreEqual ("5", attr.MarshalCookie, "#H3");
368                         Assert.AreEqual (typeof (Marshal1), Type.GetType (attr.MarshalType), "#H4");
369
370                         // bug #82465
371                         attrs = typeof (Class2).GetField ("f3").GetCustomAttributes (true);
372                         Assert.AreEqual (1, attrs.Length, "#I1");
373                         attr = (MarshalAsAttribute) attrs [0];
374                         Assert.AreEqual (UnmanagedType.CustomMarshaler, attr.Value, "#I2");
375                         Assert.AreEqual ("5", attr.MarshalCookie, "#I3");
376                         Assert.AreEqual (typeof (Marshal1), Type.GetType (attr.MarshalType), "#I4");
377                 }
378
379                 class Foo {
380                         public static int static_field;
381                         public int field;
382                 }
383
384                 [ExpectedException (typeof (ArgumentException))]
385                 public void GetValueWrongObject ()
386                 {
387                         Foo f = new Foo ();
388
389                         typeof (Foo).GetField ("field").GetValue (typeof (int));
390                 }
391
392                 public void GetValueWrongObjectStatic ()
393                 {
394                         Foo f = new Foo ();
395
396                         // This is allowed in MS.NET
397                         typeof (Foo).GetField ("static_field").GetValue (typeof (int));
398                 }
399
400 #if !TARGET_JVM // ReflectionOnlyLoad not supported for TARGET_JVM
401                 [Test]
402                 [ExpectedException (typeof (InvalidOperationException))]
403                 public void GetValueOnRefOnlyAssembly ()
404                 {
405                         Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (FieldInfoTest).Assembly.FullName);
406                         Type t = assembly.GetType (typeof (RefOnlyFieldClass).FullName);
407                         FieldInfo f = t.GetField ("RefOnlyField", BindingFlags.Static | BindingFlags.NonPublic);
408                         f.GetValue (null);
409                 }
410         
411                 [Test]
412                 [ExpectedException (typeof (InvalidOperationException))]
413                 public void SetValueOnRefOnlyAssembly ()
414                 {
415                         Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (FieldInfoTest).Assembly.FullName);
416                         Type t = assembly.GetType (typeof (RefOnlyFieldClass).FullName);
417                         FieldInfo f = t.GetField ("RefOnlyField", BindingFlags.Static | BindingFlags.NonPublic);
418                         f.SetValue (null, 8);
419                 }
420 #endif // TARGET_JVM
421
422                 const int literal = 42;
423
424                 [Test]
425                 [ExpectedException (typeof (FieldAccessException))]
426                 public void SetValueOnLiteralField ()
427                 {
428                         FieldInfo f = typeof (FieldInfoTest).GetField ("literal", BindingFlags.Static | BindingFlags.NonPublic);
429                         f.SetValue (null, 0);
430                 }
431
432                 public int? nullable_field;
433
434                 public static int? static_nullable_field;
435
436                 [Test]
437                 public void NullableTests ()
438                 {
439                         FieldInfoTest t = new FieldInfoTest ();
440
441                         FieldInfo fi = typeof (FieldInfoTest).GetField ("nullable_field");
442
443                         fi.SetValue (t, 101);
444                         Assert.AreEqual (101, fi.GetValue (t));
445                         fi.SetValue (t, null);
446                         Assert.AreEqual (null, fi.GetValue (t));
447
448                         FieldInfo fi2 = typeof (FieldInfoTest).GetField ("static_nullable_field");
449
450                         fi2.SetValue (t, 101);
451                         Assert.AreEqual (101, fi2.GetValue (t));
452                         fi2.SetValue (t, null);
453                         Assert.AreEqual (null, fi2.GetValue (t));
454                 }
455         
456 #if !TARGET_JVM // TypeBuilder not supported for TARGET_JVM
457                 [Test]
458                 public void NonPublicTests ()
459                 {
460                         Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (FieldInfoTest).Assembly.FullName);
461                 
462                         Type t = assembly.GetType (typeof (NonPublicFieldClass).FullName);
463
464                         // try to get non-public field
465                         FieldInfo fi = t.GetField ("protectedField");
466                         Assert.IsNull (fi);
467                         // get it for real
468                         fi = t.GetField ("protectedField", BindingFlags.NonPublic | BindingFlags.Instance);
469                         Assert.IsNotNull (fi);
470                 }
471 #endif // TARGET_JVM
472
473                 [Test]
474                 public void GetRawDefaultValue ()
475                 {
476                         Assert.AreEqual (5, typeof (FieldInfoTest).GetField ("int_field").GetRawConstantValue ());
477                         Assert.AreEqual (Int64.MaxValue, typeof (FieldInfoTest).GetField ("long_field").GetRawConstantValue ());
478                         Assert.AreEqual (2, typeof (FieldInfoTest).GetField ("int_enum_field").GetRawConstantValue ());
479                         Assert.AreEqual (typeof (int), typeof (FieldInfoTest).GetField ("int_enum_field").GetRawConstantValue ().GetType ());
480                         Assert.AreEqual (2, typeof (FieldInfoTest).GetField ("long_enum_field").GetRawConstantValue ());
481                         Assert.AreEqual (typeof (long), typeof (FieldInfoTest).GetField ("long_enum_field").GetRawConstantValue ().GetType ());
482                         Assert.AreEqual ("Hello", typeof (FieldInfoTest).GetField ("string_field").GetRawConstantValue ());
483                         Assert.AreEqual (null, typeof (FieldInfoTest).GetField ("object_field").GetRawConstantValue ());
484                 }
485
486                 [Test]
487                 [ExpectedException (typeof (InvalidOperationException))]
488                 public void GetRawDefaultValueNoDefault ()
489                 {
490                         typeof (FieldInfoTest).GetField ("non_const_field").GetRawConstantValue ();
491                 }
492
493                 [Test]
494                 [ExpectedException (typeof (InvalidOperationException))]
495                 public void GetValueOpenGeneric ()
496                 {
497                         typeof(Foo<>).GetField ("field").GetValue (null);
498                 }
499
500                 [Test]
501                 [ExpectedException (typeof (InvalidOperationException))]
502                 public void SetValueOpenGeneric ()
503                 {
504                         typeof(Foo<>).GetField ("field").SetValue (null, 0);
505                 }
506
507                 [Test]
508                 public void GetValueOnConstantOfOpenGeneric ()
509                 {
510                         Assert.AreEqual (10, typeof(Foo<>).GetField ("constant").GetValue (null), "#1");
511                         Assert.AreEqual ("waa", typeof(Foo<>).GetField ("sconstant").GetValue (null), "#2");
512                         Assert.AreEqual (IntEnum.Third, typeof(Foo<>).GetField ("econstant").GetValue (null), "#3");
513                 }
514
515                 public static unsafe void* ip;
516
517                 [Test]
518                 public unsafe void GetSetValuePointers ()
519                 {
520                         int i = 5;
521                         void *p = &i;
522                         typeof (FieldInfoTest).GetField ("ip").SetValue (null, (IntPtr)p);
523                         Pointer p2 = (Pointer)typeof (FieldInfoTest).GetField ("ip").GetValue (null);
524
525                         int *pi = (int*)Pointer.Unbox (p2);
526                         Assert.AreEqual (5, *pi);
527
528                         typeof (FieldInfoTest).GetField ("ip").SetValue (null, (UIntPtr)p);
529                         p2 = (Pointer)typeof (FieldInfoTest).GetField ("ip").GetValue (null);
530
531                         pi = (int*)Pointer.Unbox (p2);
532                         Assert.AreEqual (5, *pi);
533                 }
534
535                 [Test]
536                 public void SetValuePrimitiveConversions ()
537                 {
538                         FieldInfo field;
539                         var instance = new FieldInvokeMatrix ();
540                         var fh = typeof (FieldInvokeMatrix);
541
542                         field = fh.GetField ("field_Byte");                     
543                         field.SetValue (instance, Byte.MaxValue);
544                         Assert.AreEqual (Byte.MaxValue, instance.field_Byte);
545                         Throws (field, instance, SByte.MaxValue);
546                         Throws (field, instance, true);
547                         Throws (field, instance, Char.MaxValue);
548                         Throws (field, instance, Int16.MaxValue);
549                         Throws (field, instance, UInt16.MaxValue);
550                         Throws (field, instance, Int32.MaxValue);
551                         Throws (field, instance, UInt32.MaxValue);
552                         Throws (field, instance, Int64.MaxValue);
553                         Throws (field, instance, UInt64.MaxValue);
554                         Throws (field, instance, Single.MaxValue);
555                         Throws (field, instance, Double.MaxValue);
556                         Throws (field, instance, IntPtr.Zero);
557                         Throws (field, instance, UIntPtr.Zero);
558                         Throws (field, instance, Decimal.MaxValue);
559                         Throws (field, instance, DateTime.MaxValue);
560                         field.SetValue (instance, ByteEnum.MaxValue);
561                         Assert.AreEqual (Byte.MaxValue, instance.field_Byte);
562                         Throws (field, instance, SByteEnum.MaxValue);
563                         Throws (field, instance, Int16Enum.MaxValue);
564                         Throws (field, instance, UInt16Enum.MaxValue);
565                         Throws (field, instance, Int32Enum.MaxValue);
566                         Throws (field, instance, UInt32Enum.MaxValue);
567                         Throws (field, instance, Int64Enum.MaxValue);
568                         Throws (field, instance, UInt64Enum.MaxValue);
569                         field = fh.GetField ("field_SByte");
570                         Throws (field, instance, Byte.MaxValue);
571                         field.SetValue (instance, SByte.MaxValue);
572                         Assert.AreEqual (SByte.MaxValue, instance.field_SByte);
573                         Throws (field, instance, true);
574                         Throws (field, instance, Char.MaxValue);
575                         Throws (field, instance, Int16.MaxValue);
576                         Throws (field, instance, UInt16.MaxValue);
577                         Throws (field, instance, Int32.MaxValue);
578                         Throws (field, instance, UInt32.MaxValue);
579                         Throws (field, instance, Int64.MaxValue);
580                         Throws (field, instance, UInt64.MaxValue);
581                         Throws (field, instance, Single.MaxValue);
582                         Throws (field, instance, Double.MaxValue);
583                         Throws (field, instance, IntPtr.Zero);
584                         Throws (field, instance, UIntPtr.Zero);
585                         Throws (field, instance, Decimal.MaxValue);
586                         Throws (field, instance, DateTime.MaxValue);
587                         Throws (field, instance, ByteEnum.MaxValue);
588                         field.SetValue (instance, SByteEnum.MaxValue);
589                         Assert.AreEqual (SByte.MaxValue, instance.field_SByte);
590                         Throws (field, instance, Int16Enum.MaxValue);
591                         Throws (field, instance, UInt16Enum.MaxValue);
592                         Throws (field, instance, Int32Enum.MaxValue);
593                         Throws (field, instance, UInt32Enum.MaxValue);
594                         Throws (field, instance, Int64Enum.MaxValue);
595                         Throws (field, instance, UInt64Enum.MaxValue);
596                         field = fh.GetField ("field_Boolean");
597                         Throws (field, instance, Byte.MaxValue);
598                         Throws (field, instance, SByte.MaxValue);
599                         field.SetValue (instance, true);
600                         Assert.AreEqual (true, instance.field_Boolean);
601                         Throws (field, instance, Char.MaxValue);
602                         Throws (field, instance, Int16.MaxValue);
603                         Throws (field, instance, UInt16.MaxValue);
604                         Throws (field, instance, Int32.MaxValue);
605                         Throws (field, instance, UInt32.MaxValue);
606                         Throws (field, instance, Int64.MaxValue);
607                         Throws (field, instance, UInt64.MaxValue);
608                         Throws (field, instance, Single.MaxValue);
609                         Throws (field, instance, Double.MaxValue);
610                         Throws (field, instance, IntPtr.Zero);
611                         Throws (field, instance, UIntPtr.Zero);
612                         Throws (field, instance, Decimal.MaxValue);
613                         Throws (field, instance, DateTime.MaxValue);
614                         Throws (field, instance, ByteEnum.MaxValue);
615                         Throws (field, instance, SByteEnum.MaxValue);
616                         Throws (field, instance, Int16Enum.MaxValue);
617                         Throws (field, instance, UInt16Enum.MaxValue);
618                         Throws (field, instance, Int32Enum.MaxValue);
619                         Throws (field, instance, UInt32Enum.MaxValue);
620                         Throws (field, instance, Int64Enum.MaxValue);
621                         Throws (field, instance, UInt64Enum.MaxValue);
622                         field = fh.GetField ("field_Char");
623                         field.SetValue (instance, Byte.MaxValue);
624                         Assert.AreEqual (Byte.MaxValue, instance.field_Char);
625                         Throws (field, instance, SByte.MaxValue);
626                         Throws (field, instance, true);
627                         field.SetValue (instance, Char.MaxValue);
628                         Assert.AreEqual (Char.MaxValue, instance.field_Char);
629                         Throws (field, instance, Int16.MaxValue);
630                         field.SetValue (instance, UInt16.MaxValue);
631                         Assert.AreEqual (UInt16.MaxValue, instance.field_Char);
632                         Throws (field, instance, Int32.MaxValue);
633                         Throws (field, instance, UInt32.MaxValue);
634                         Throws (field, instance, Int64.MaxValue);
635                         Throws (field, instance, UInt64.MaxValue);
636                         Throws (field, instance, Single.MaxValue);
637                         Throws (field, instance, Double.MaxValue);
638                         Throws (field, instance, IntPtr.Zero);
639                         Throws (field, instance, UIntPtr.Zero);
640                         Throws (field, instance, Decimal.MaxValue);
641                         Throws (field, instance, DateTime.MaxValue);
642                         field.SetValue (instance, ByteEnum.MaxValue);
643                         Assert.AreEqual (Byte.MaxValue, instance.field_Char);
644                         Throws (field, instance, SByteEnum.MaxValue);
645                         Throws (field, instance, Int16Enum.MaxValue);
646                         field.SetValue (instance, UInt16Enum.MaxValue);
647                         Assert.AreEqual (UInt16.MaxValue, instance.field_Char);
648                         Throws (field, instance, Int32Enum.MaxValue);
649                         Throws (field, instance, UInt32Enum.MaxValue);
650                         Throws (field, instance, Int64Enum.MaxValue);
651                         Throws (field, instance, UInt64Enum.MaxValue);
652                         field = fh.GetField ("field_Int16");
653                         field.SetValue (instance, Byte.MaxValue);
654                         Assert.AreEqual (Byte.MaxValue, instance.field_Int16);
655                         field.SetValue (instance, SByte.MaxValue);
656                         Assert.AreEqual (SByte.MaxValue, instance.field_Int16);
657                         Throws (field, instance, true);
658                         Throws (field, instance, Char.MaxValue);
659                         field.SetValue (instance, Int16.MaxValue);
660                         Assert.AreEqual (Int16.MaxValue, instance.field_Int16);
661                         Throws (field, instance, UInt16.MaxValue);
662                         Throws (field, instance, Int32.MaxValue);
663                         Throws (field, instance, UInt32.MaxValue);
664                         Throws (field, instance, Int64.MaxValue);
665                         Throws (field, instance, UInt64.MaxValue);
666                         Throws (field, instance, Single.MaxValue);
667                         Throws (field, instance, Double.MaxValue);
668                         Throws (field, instance, IntPtr.Zero);
669                         Throws (field, instance, UIntPtr.Zero);
670                         Throws (field, instance, Decimal.MaxValue);
671                         Throws (field, instance, DateTime.MaxValue);
672                         field.SetValue (instance, ByteEnum.MaxValue);
673                         Assert.AreEqual (Byte.MaxValue, instance.field_Int16);
674                         field.SetValue (instance, SByteEnum.MaxValue);
675                         Assert.AreEqual (SByte.MaxValue, instance.field_Int16);
676                         field.SetValue (instance, Int16Enum.MaxValue);
677                         Assert.AreEqual (Int16.MaxValue, instance.field_Int16);
678                         Throws (field, instance, UInt16Enum.MaxValue);
679                         Throws (field, instance, Int32Enum.MaxValue);
680                         Throws (field, instance, UInt32Enum.MaxValue);
681                         Throws (field, instance, Int64Enum.MaxValue);
682                         Throws (field, instance, UInt64Enum.MaxValue);
683                         field = fh.GetField ("field_UInt16");
684                         field.SetValue (instance, Byte.MaxValue);
685                         Assert.AreEqual (Byte.MaxValue, instance.field_UInt16);
686                         Throws (field, instance, SByte.MaxValue);
687                         Throws (field, instance, true);
688                         field.SetValue (instance, Char.MaxValue);
689                         Assert.AreEqual (Char.MaxValue, instance.field_UInt16);
690                         Throws (field, instance, Int16.MaxValue);
691                         field.SetValue (instance, UInt16.MaxValue);
692                         Assert.AreEqual (UInt16.MaxValue, instance.field_UInt16);
693                         Throws (field, instance, Int32.MaxValue);
694                         Throws (field, instance, UInt32.MaxValue);
695                         Throws (field, instance, Int64.MaxValue);
696                         Throws (field, instance, UInt64.MaxValue);
697                         Throws (field, instance, Single.MaxValue);
698                         Throws (field, instance, Double.MaxValue);
699                         Throws (field, instance, IntPtr.Zero);
700                         Throws (field, instance, UIntPtr.Zero);
701                         Throws (field, instance, Decimal.MaxValue);
702                         Throws (field, instance, DateTime.MaxValue);
703                         field.SetValue (instance, ByteEnum.MaxValue);
704                         Assert.AreEqual (Byte.MaxValue, instance.field_UInt16);
705                         Throws (field, instance, SByteEnum.MaxValue);
706                         Throws (field, instance, Int16Enum.MaxValue);
707                         field.SetValue (instance, UInt16Enum.MaxValue);
708                         Assert.AreEqual (UInt16.MaxValue, instance.field_UInt16);
709                         Throws (field, instance, Int32Enum.MaxValue);
710                         Throws (field, instance, UInt32Enum.MaxValue);
711                         Throws (field, instance, Int64Enum.MaxValue);
712                         Throws (field, instance, UInt64Enum.MaxValue);
713                         field = fh.GetField ("field_Int32");
714                         field.SetValue (instance, Byte.MaxValue);
715                         Assert.AreEqual (Byte.MaxValue, instance.field_Int32);
716                         field.SetValue (instance, SByte.MaxValue);
717                         Assert.AreEqual (SByte.MaxValue, instance.field_Int32);
718                         Throws (field, instance, true);
719                         field.SetValue (instance, Char.MaxValue);
720                         Assert.AreEqual (Char.MaxValue, instance.field_Int32);
721                         field.SetValue (instance, Int16.MaxValue);
722                         Assert.AreEqual (Int16.MaxValue, instance.field_Int32);
723                         field.SetValue (instance, UInt16.MaxValue);
724                         Assert.AreEqual (UInt16.MaxValue, instance.field_Int32);
725                         field.SetValue (instance, Int32.MaxValue);
726                         Assert.AreEqual (Int32.MaxValue, instance.field_Int32);
727                         Throws (field, instance, UInt32.MaxValue);
728                         Throws (field, instance, Int64.MaxValue);
729                         Throws (field, instance, UInt64.MaxValue);
730                         Throws (field, instance, Single.MaxValue);
731                         Throws (field, instance, Double.MaxValue);
732                         Throws (field, instance, IntPtr.Zero);
733                         Throws (field, instance, UIntPtr.Zero);
734                         Throws (field, instance, Decimal.MaxValue);
735                         Throws (field, instance, DateTime.MaxValue);
736                         field.SetValue (instance, ByteEnum.MaxValue);
737                         Assert.AreEqual (Byte.MaxValue, instance.field_Int32);
738                         field.SetValue (instance, SByteEnum.MaxValue);
739                         Assert.AreEqual (SByte.MaxValue, instance.field_Int32);
740                         field.SetValue (instance, Int16Enum.MaxValue);
741                         Assert.AreEqual (Int16.MaxValue, instance.field_Int32);
742                         field.SetValue (instance, UInt16Enum.MaxValue);
743                         Assert.AreEqual (UInt16.MaxValue, instance.field_Int32);
744                         field.SetValue (instance, Int32Enum.MaxValue);
745                         Assert.AreEqual (Int32.MaxValue, instance.field_Int32);
746                         Throws (field, instance, UInt32Enum.MaxValue);
747                         Throws (field, instance, Int64Enum.MaxValue);
748                         Throws (field, instance, UInt64Enum.MaxValue);
749                         field = fh.GetField ("field_UInt32");
750                         field.SetValue (instance, Byte.MaxValue);
751                         Assert.AreEqual (Byte.MaxValue, instance.field_UInt32);
752                         Throws (field, instance, SByte.MaxValue);
753                         Throws (field, instance, true);
754                         field.SetValue (instance, Char.MaxValue);
755                         Assert.AreEqual (Char.MaxValue, instance.field_UInt32);
756                         Throws (field, instance, Int16.MaxValue);
757                         field.SetValue (instance, UInt16.MaxValue);
758                         Assert.AreEqual (UInt16.MaxValue, instance.field_UInt32);
759                         Throws (field, instance, Int32.MaxValue);
760                         field.SetValue (instance, UInt32.MaxValue);
761                         Assert.AreEqual (UInt32.MaxValue, instance.field_UInt32);
762                         Throws (field, instance, Int64.MaxValue);
763                         Throws (field, instance, UInt64.MaxValue);
764                         Throws (field, instance, Single.MaxValue);
765                         Throws (field, instance, Double.MaxValue);
766                         Throws (field, instance, IntPtr.Zero);
767                         Throws (field, instance, UIntPtr.Zero);
768                         Throws (field, instance, Decimal.MaxValue);
769                         Throws (field, instance, DateTime.MaxValue);
770                         field.SetValue (instance, ByteEnum.MaxValue);
771                         Assert.AreEqual (Byte.MaxValue, instance.field_UInt32);
772                         Throws (field, instance, SByteEnum.MaxValue);
773                         Throws (field, instance, Int16Enum.MaxValue);
774                         field.SetValue (instance, UInt16Enum.MaxValue);
775                         Assert.AreEqual (UInt16.MaxValue, instance.field_UInt32);
776                         Throws (field, instance, Int32Enum.MaxValue);
777                         field.SetValue (instance, UInt32Enum.MaxValue);
778                         Assert.AreEqual (UInt32.MaxValue, instance.field_UInt32);
779                         Throws (field, instance, Int64Enum.MaxValue);
780                         Throws (field, instance, UInt64Enum.MaxValue);
781                         field = fh.GetField ("field_Int64");
782                         field.SetValue (instance, Byte.MaxValue);
783                         Assert.AreEqual (Byte.MaxValue, instance.field_Int64);
784                         field.SetValue (instance, SByte.MaxValue);
785                         Assert.AreEqual (SByte.MaxValue, instance.field_Int64);
786                         Throws (field, instance, true);
787                         field.SetValue (instance, Char.MaxValue);
788                         Assert.AreEqual (Char.MaxValue, instance.field_Int64);
789                         field.SetValue (instance, Int16.MaxValue);
790                         Assert.AreEqual (Int16.MaxValue, instance.field_Int64);
791                         field.SetValue (instance, UInt16.MaxValue);
792                         Assert.AreEqual (UInt16.MaxValue, instance.field_Int64);
793                         field.SetValue (instance, Int32.MaxValue);
794                         Assert.AreEqual (Int32.MaxValue, instance.field_Int64);
795                         field.SetValue (instance, UInt32.MaxValue);
796                         Assert.AreEqual (UInt32.MaxValue, instance.field_Int64);
797                         field.SetValue (instance, Int64.MaxValue);
798                         Assert.AreEqual (Int64.MaxValue, instance.field_Int64);
799                         Throws (field, instance, UInt64.MaxValue);
800                         Throws (field, instance, Single.MaxValue);
801                         Throws (field, instance, Double.MaxValue);
802                         Throws (field, instance, IntPtr.Zero);
803                         Throws (field, instance, UIntPtr.Zero);
804                         Throws (field, instance, Decimal.MaxValue);
805                         Throws (field, instance, DateTime.MaxValue);
806                         field.SetValue (instance, ByteEnum.MaxValue);
807                         Assert.AreEqual (Byte.MaxValue, instance.field_Int64);
808                         field.SetValue (instance, SByteEnum.MaxValue);
809                         Assert.AreEqual (SByte.MaxValue, instance.field_Int64);
810                         field.SetValue (instance, Int16Enum.MaxValue);
811                         Assert.AreEqual (Int16.MaxValue, instance.field_Int64);
812                         field.SetValue (instance, UInt16Enum.MaxValue);
813                         Assert.AreEqual (UInt16.MaxValue, instance.field_Int64);
814                         field.SetValue (instance, Int32Enum.MaxValue);
815                         Assert.AreEqual (Int32.MaxValue, instance.field_Int64);
816                         field.SetValue (instance, UInt32Enum.MaxValue);
817                         Assert.AreEqual (UInt32.MaxValue, instance.field_Int64);
818                         field.SetValue (instance, Int64Enum.MaxValue);
819                         Assert.AreEqual (Int64.MaxValue, instance.field_Int64);
820                         Throws (field, instance, UInt64Enum.MaxValue);
821                         field = fh.GetField ("field_UInt64");
822                         field.SetValue (instance, Byte.MaxValue);
823                         Assert.AreEqual (Byte.MaxValue, instance.field_UInt64);
824                         Throws (field, instance, SByte.MaxValue);
825                         Throws (field, instance, true);
826                         field.SetValue (instance, Char.MaxValue);
827                         Assert.AreEqual (Char.MaxValue, instance.field_UInt64);
828                         Throws (field, instance, Int16.MaxValue);
829                         field.SetValue (instance, UInt16.MaxValue);
830                         Assert.AreEqual (UInt16.MaxValue, instance.field_UInt64);
831                         Throws (field, instance, Int32.MaxValue);
832                         field.SetValue (instance, UInt32.MaxValue);
833                         Assert.AreEqual (UInt32.MaxValue, instance.field_UInt64);
834                         Throws (field, instance, Int64.MaxValue);
835                         field.SetValue (instance, UInt64.MaxValue);
836                         Assert.AreEqual (UInt64.MaxValue, instance.field_UInt64);
837                         Throws (field, instance, Single.MaxValue);
838                         Throws (field, instance, Double.MaxValue);
839                         Throws (field, instance, IntPtr.Zero);
840                         Throws (field, instance, UIntPtr.Zero);
841                         Throws (field, instance, Decimal.MaxValue);
842                         Throws (field, instance, DateTime.MaxValue);
843                         field.SetValue (instance, ByteEnum.MaxValue);
844                         Assert.AreEqual (Byte.MaxValue, instance.field_UInt64);
845                         Throws (field, instance, SByteEnum.MaxValue);
846                         Throws (field, instance, Int16Enum.MaxValue);
847                         field.SetValue (instance, UInt16Enum.MaxValue);
848                         Assert.AreEqual (UInt16.MaxValue, instance.field_UInt64);
849                         Throws (field, instance, Int32Enum.MaxValue);
850                         field.SetValue (instance, UInt32Enum.MaxValue);
851                         Assert.AreEqual (UInt32.MaxValue, instance.field_UInt64);
852                         Throws (field, instance, Int64Enum.MaxValue);
853                         field.SetValue (instance, UInt64Enum.MaxValue);
854                         Assert.AreEqual (UInt64.MaxValue, instance.field_UInt64);
855                         field = fh.GetField ("field_Single");
856                         field.SetValue (instance, Byte.MaxValue);
857                         Assert.AreEqual (Byte.MaxValue, instance.field_Single);
858                         field.SetValue (instance, SByte.MaxValue);
859                         Assert.AreEqual (SByte.MaxValue, instance.field_Single);
860                         Throws (field, instance, true);
861                         field.SetValue (instance, Char.MaxValue);
862                         Assert.AreEqual ((Single) Char.MaxValue, instance.field_Single);
863                         field.SetValue (instance, Int16.MaxValue);
864                         Assert.AreEqual (Int16.MaxValue, instance.field_Single);
865                         field.SetValue (instance, UInt16.MaxValue);
866                         Assert.AreEqual (UInt16.MaxValue, instance.field_Single);
867                         field.SetValue (instance, Int32.MaxValue);
868                         Assert.AreEqual ((Single)Int32.MaxValue, instance.field_Single);
869                         field.SetValue (instance, UInt32.MaxValue);
870                         Assert.AreEqual ((Single) UInt32.MaxValue, instance.field_Single);
871                         field.SetValue (instance, Int64.MaxValue);
872                         Assert.AreEqual (Int64.MaxValue, instance.field_Single);
873                         field.SetValue (instance, UInt64.MaxValue);
874                         Assert.AreEqual (UInt64.MaxValue, instance.field_Single);
875                         field.SetValue (instance, Single.MaxValue);
876                         Assert.AreEqual (Single.MaxValue, instance.field_Single);
877                         Throws (field, instance, Double.MaxValue);
878                         Throws (field, instance, IntPtr.Zero);
879                         Throws (field, instance, UIntPtr.Zero);
880                         Throws (field, instance, Decimal.MaxValue);
881                         Throws (field, instance, DateTime.MaxValue);
882                         field.SetValue (instance, ByteEnum.MaxValue);
883                         Assert.AreEqual (Byte.MaxValue, instance.field_Single);
884                         field.SetValue (instance, SByteEnum.MaxValue);
885                         Assert.AreEqual (SByte.MaxValue, instance.field_Single);
886                         field.SetValue (instance, Int16Enum.MaxValue);
887                         Assert.AreEqual (Int16.MaxValue, instance.field_Single);
888                         field.SetValue (instance, UInt16Enum.MaxValue);
889                         Assert.AreEqual (UInt16.MaxValue, instance.field_Single);
890                         field.SetValue (instance, Int32Enum.MaxValue);
891                         Assert.AreEqual ((Single) Int32.MaxValue, instance.field_Single);
892                         field.SetValue (instance, UInt32Enum.MaxValue);
893                         Assert.AreEqual ((Single) UInt32.MaxValue, instance.field_Single);
894                         field.SetValue (instance, Int64Enum.MaxValue);
895                         Assert.AreEqual (Int64.MaxValue, instance.field_Single);
896                         field.SetValue (instance, UInt64Enum.MaxValue);
897                         Assert.AreEqual (UInt64.MaxValue, instance.field_Single);
898                         field = fh.GetField ("field_Double");
899                         field.SetValue (instance, Byte.MaxValue);
900                         Assert.AreEqual (Byte.MaxValue, instance.field_Double);
901                         field.SetValue (instance, SByte.MaxValue);
902                         Assert.AreEqual (SByte.MaxValue, instance.field_Double);
903                         Throws (field, instance, true);
904                         field.SetValue (instance, Char.MaxValue);
905                         Assert.AreEqual ((Double) Char.MaxValue, instance.field_Double);
906                         field.SetValue (instance, Int16.MaxValue);
907                         Assert.AreEqual (Int16.MaxValue, instance.field_Double);
908                         field.SetValue (instance, UInt16.MaxValue);
909                         Assert.AreEqual (UInt16.MaxValue, instance.field_Double);
910                         field.SetValue (instance, Int32.MaxValue);
911                         Assert.AreEqual (Int32.MaxValue, instance.field_Double);
912                         field.SetValue (instance, UInt32.MaxValue);
913                         Assert.AreEqual (UInt32.MaxValue, instance.field_Double);
914                         field.SetValue (instance, Int64.MaxValue);
915                         Assert.AreEqual (Int64.MaxValue, instance.field_Double);
916                         field.SetValue (instance, UInt64.MaxValue);
917                         Assert.AreEqual (UInt64.MaxValue, instance.field_Double);
918                         field.SetValue (instance, Single.MaxValue);
919                         Assert.AreEqual (Single.MaxValue, instance.field_Double);
920                         field.SetValue (instance, Double.MaxValue);
921                         Assert.AreEqual (Double.MaxValue, instance.field_Double);
922                         Throws (field, instance, IntPtr.Zero);
923                         Throws (field, instance, UIntPtr.Zero);
924                         Throws (field, instance, Decimal.MaxValue);
925                         Throws (field, instance, DateTime.MaxValue);
926                         field.SetValue (instance, ByteEnum.MaxValue);
927                         Assert.AreEqual (Byte.MaxValue, instance.field_Double);
928                         field.SetValue (instance, SByteEnum.MaxValue);
929                         Assert.AreEqual (SByte.MaxValue, instance.field_Double);
930                         field.SetValue (instance, Int16Enum.MaxValue);
931                         Assert.AreEqual (Int16.MaxValue, instance.field_Double);
932                         field.SetValue (instance, UInt16Enum.MaxValue);
933                         Assert.AreEqual (UInt16.MaxValue, instance.field_Double);
934                         field.SetValue (instance, Int32Enum.MaxValue);
935                         Assert.AreEqual (Int32.MaxValue, instance.field_Double);
936                         field.SetValue (instance, UInt32Enum.MaxValue);
937                         Assert.AreEqual (UInt32.MaxValue, instance.field_Double);
938                         field.SetValue (instance, Int64Enum.MaxValue);
939                         Assert.AreEqual (Int64.MaxValue, instance.field_Double);
940                         field.SetValue (instance, UInt64Enum.MaxValue);
941                         Assert.AreEqual (UInt64.MaxValue, instance.field_Double);
942                         field = fh.GetField ("field_IntPtr");
943                         Throws (field, instance, Byte.MaxValue);
944                         Throws (field, instance, SByte.MaxValue);
945                         Throws (field, instance, true);
946                         Throws (field, instance, Char.MaxValue);
947                         Throws (field, instance, Int16.MaxValue);
948                         Throws (field, instance, UInt16.MaxValue);
949                         Throws (field, instance, Int32.MaxValue);
950                         Throws (field, instance, UInt32.MaxValue);
951                         Throws (field, instance, Int64.MaxValue);
952                         Throws (field, instance, UInt64.MaxValue);
953                         Throws (field, instance, Single.MaxValue);
954                         Throws (field, instance, Double.MaxValue);
955                         field.SetValue (instance, IntPtr.Zero);
956                         Assert.AreEqual (IntPtr.Zero, instance.field_IntPtr);
957                         Throws (field, instance, UIntPtr.Zero);
958                         Throws (field, instance, Decimal.MaxValue);
959                         Throws (field, instance, DateTime.MaxValue);
960                         Throws (field, instance, ByteEnum.MaxValue);
961                         Throws (field, instance, SByteEnum.MaxValue);
962                         Throws (field, instance, Int16Enum.MaxValue);
963                         Throws (field, instance, UInt16Enum.MaxValue);
964                         Throws (field, instance, Int32Enum.MaxValue);
965                         Throws (field, instance, UInt32Enum.MaxValue);
966                         Throws (field, instance, Int64Enum.MaxValue);
967                         Throws (field, instance, UInt64Enum.MaxValue);
968                         field = fh.GetField ("field_UIntPtr");
969                         Throws (field, instance, Byte.MaxValue);
970                         Throws (field, instance, SByte.MaxValue);
971                         Throws (field, instance, true);
972                         Throws (field, instance, Char.MaxValue);
973                         Throws (field, instance, Int16.MaxValue);
974                         Throws (field, instance, UInt16.MaxValue);
975                         Throws (field, instance, Int32.MaxValue);
976                         Throws (field, instance, UInt32.MaxValue);
977                         Throws (field, instance, Int64.MaxValue);
978                         Throws (field, instance, UInt64.MaxValue);
979                         Throws (field, instance, Single.MaxValue);
980                         Throws (field, instance, Double.MaxValue);
981                         Throws (field, instance, IntPtr.Zero);
982                         field.SetValue (instance, UIntPtr.Zero);
983                         Assert.AreEqual (UIntPtr.Zero, instance.field_UIntPtr);
984                         Throws (field, instance, Decimal.MaxValue);
985                         Throws (field, instance, DateTime.MaxValue);
986                         Throws (field, instance, ByteEnum.MaxValue);
987                         Throws (field, instance, SByteEnum.MaxValue);
988                         Throws (field, instance, Int16Enum.MaxValue);
989                         Throws (field, instance, UInt16Enum.MaxValue);
990                         Throws (field, instance, Int32Enum.MaxValue);
991                         Throws (field, instance, UInt32Enum.MaxValue);
992                         Throws (field, instance, Int64Enum.MaxValue);
993                         Throws (field, instance, UInt64Enum.MaxValue);
994                         field = fh.GetField ("field_Decimal");
995                         Throws (field, instance, Byte.MaxValue);
996                         Throws (field, instance, SByte.MaxValue);
997                         Throws (field, instance, true);
998                         Throws (field, instance, Char.MaxValue);
999                         Throws (field, instance, Int16.MaxValue);
1000                         Throws (field, instance, UInt16.MaxValue);
1001                         Throws (field, instance, Int32.MaxValue);
1002                         Throws (field, instance, UInt32.MaxValue);
1003                         Throws (field, instance, Int64.MaxValue);
1004                         Throws (field, instance, UInt64.MaxValue);
1005                         Throws (field, instance, Single.MaxValue);
1006                         Throws (field, instance, Double.MaxValue);
1007                         Throws (field, instance, IntPtr.Zero);
1008                         Throws (field, instance, UIntPtr.Zero);
1009                         field.SetValue (instance, Decimal.MaxValue);
1010                         Assert.AreEqual (Decimal.MaxValue, instance.field_Decimal);
1011                         Throws (field, instance, DateTime.MaxValue);
1012                         Throws (field, instance, ByteEnum.MaxValue);
1013                         Throws (field, instance, SByteEnum.MaxValue);
1014                         Throws (field, instance, Int16Enum.MaxValue);
1015                         Throws (field, instance, UInt16Enum.MaxValue);
1016                         Throws (field, instance, Int32Enum.MaxValue);
1017                         Throws (field, instance, UInt32Enum.MaxValue);
1018                         Throws (field, instance, Int64Enum.MaxValue);
1019                         Throws (field, instance, UInt64Enum.MaxValue);
1020                         field = fh.GetField ("field_DateTime");
1021                         Throws (field, instance, Byte.MaxValue);
1022                         Throws (field, instance, SByte.MaxValue);
1023                         Throws (field, instance, true);
1024                         Throws (field, instance, Char.MaxValue);
1025                         Throws (field, instance, Int16.MaxValue);
1026                         Throws (field, instance, UInt16.MaxValue);
1027                         Throws (field, instance, Int32.MaxValue);
1028                         Throws (field, instance, UInt32.MaxValue);
1029                         Throws (field, instance, Int64.MaxValue);
1030                         Throws (field, instance, UInt64.MaxValue);
1031                         Throws (field, instance, Single.MaxValue);
1032                         Throws (field, instance, Double.MaxValue);
1033                         Throws (field, instance, IntPtr.Zero);
1034                         Throws (field, instance, UIntPtr.Zero);
1035                         Throws (field, instance, Decimal.MaxValue);
1036                         field.SetValue (instance, DateTime.MaxValue);
1037                         Assert.AreEqual (DateTime.MaxValue, instance.field_DateTime);
1038                         Throws (field, instance, ByteEnum.MaxValue);
1039                         Throws (field, instance, SByteEnum.MaxValue);
1040                         Throws (field, instance, Int16Enum.MaxValue);
1041                         Throws (field, instance, UInt16Enum.MaxValue);
1042                         Throws (field, instance, Int32Enum.MaxValue);
1043                         Throws (field, instance, UInt32Enum.MaxValue);
1044                         Throws (field, instance, Int64Enum.MaxValue);
1045                         Throws (field, instance, UInt64Enum.MaxValue);
1046                         field = fh.GetField ("field_ByteEnum");
1047                         field.SetValue (instance, Byte.MaxValue);
1048                         Assert.AreEqual (ByteEnum.MaxValue, instance.field_ByteEnum);
1049                         Throws (field, instance, SByte.MaxValue);
1050                         Throws (field, instance, true);
1051                         Throws (field, instance, Char.MaxValue);
1052                         Throws (field, instance, Int16.MaxValue);
1053                         Throws (field, instance, UInt16.MaxValue);
1054                         Throws (field, instance, Int32.MaxValue);
1055                         Throws (field, instance, UInt32.MaxValue);
1056                         Throws (field, instance, Int64.MaxValue);
1057                         Throws (field, instance, UInt64.MaxValue);
1058                         Throws (field, instance, Single.MaxValue);
1059                         Throws (field, instance, Double.MaxValue);
1060                         Throws (field, instance, IntPtr.Zero);
1061                         Throws (field, instance, UIntPtr.Zero);
1062                         Throws (field, instance, Decimal.MaxValue);
1063                         Throws (field, instance, DateTime.MaxValue);
1064                         field.SetValue (instance, ByteEnum.MaxValue);
1065                         Assert.AreEqual (ByteEnum.MaxValue, instance.field_ByteEnum);
1066                         Throws (field, instance, SByteEnum.MaxValue);
1067                         Throws (field, instance, Int16Enum.MaxValue);
1068                         Throws (field, instance, UInt16Enum.MaxValue);
1069                         Throws (field, instance, Int32Enum.MaxValue);
1070                         Throws (field, instance, UInt32Enum.MaxValue);
1071                         Throws (field, instance, Int64Enum.MaxValue);
1072                         Throws (field, instance, UInt64Enum.MaxValue);
1073                         field = fh.GetField ("field_SByteEnum");
1074                         Throws (field, instance, Byte.MaxValue);
1075                         field.SetValue (instance, SByte.MaxValue);
1076                         Assert.AreEqual (SByteEnum.MaxValue, instance.field_SByteEnum);
1077                         Throws (field, instance, true);
1078                         Throws (field, instance, Char.MaxValue);
1079                         Throws (field, instance, Int16.MaxValue);
1080                         Throws (field, instance, UInt16.MaxValue);
1081                         Throws (field, instance, Int32.MaxValue);
1082                         Throws (field, instance, UInt32.MaxValue);
1083                         Throws (field, instance, Int64.MaxValue);
1084                         Throws (field, instance, UInt64.MaxValue);
1085                         Throws (field, instance, Single.MaxValue);
1086                         Throws (field, instance, Double.MaxValue);
1087                         Throws (field, instance, IntPtr.Zero);
1088                         Throws (field, instance, UIntPtr.Zero);
1089                         Throws (field, instance, Decimal.MaxValue);
1090                         Throws (field, instance, DateTime.MaxValue);
1091                         Throws (field, instance, ByteEnum.MaxValue);
1092                         field.SetValue (instance, SByteEnum.MaxValue);
1093                         Assert.AreEqual (SByteEnum.MaxValue, instance.field_SByteEnum);
1094                         Throws (field, instance, Int16Enum.MaxValue);
1095                         Throws (field, instance, UInt16Enum.MaxValue);
1096                         Throws (field, instance, Int32Enum.MaxValue);
1097                         Throws (field, instance, UInt32Enum.MaxValue);
1098                         Throws (field, instance, Int64Enum.MaxValue);
1099                         Throws (field, instance, UInt64Enum.MaxValue);
1100                         field = fh.GetField ("field_Int16Enum");
1101                         field.SetValue (instance, Byte.MaxValue);
1102                         Assert.AreEqual (Byte.MaxValue, (byte) instance.field_Int16Enum);
1103                         field.SetValue (instance, SByte.MaxValue);
1104                         Assert.AreEqual (SByte.MaxValue, (sbyte) instance.field_Int16Enum);
1105                         Throws (field, instance, true);
1106                         Throws (field, instance, Char.MaxValue);
1107                         field.SetValue (instance, Int16.MaxValue);
1108                         Assert.AreEqual (Int16Enum.MaxValue, instance.field_Int16Enum);
1109                         Throws (field, instance, UInt16.MaxValue);
1110                         Throws (field, instance, Int32.MaxValue);
1111                         Throws (field, instance, UInt32.MaxValue);
1112                         Throws (field, instance, Int64.MaxValue);
1113                         Throws (field, instance, UInt64.MaxValue);
1114                         Throws (field, instance, Single.MaxValue);
1115                         Throws (field, instance, Double.MaxValue);
1116                         Throws (field, instance, IntPtr.Zero);
1117                         Throws (field, instance, UIntPtr.Zero);
1118                         Throws (field, instance, Decimal.MaxValue);
1119                         Throws (field, instance, DateTime.MaxValue);
1120                         field.SetValue (instance, ByteEnum.MaxValue);
1121                         Assert.AreEqual (ByteEnum.MaxValue, (ByteEnum) instance.field_Int16Enum);
1122                         field.SetValue (instance, SByteEnum.MaxValue);
1123                         Assert.AreEqual (SByteEnum.MaxValue, (SByteEnum) instance.field_Int16Enum);
1124                         field.SetValue (instance, Int16Enum.MaxValue);
1125                         Assert.AreEqual (Int16Enum.MaxValue, instance.field_Int16Enum);
1126                         Throws (field, instance, UInt16Enum.MaxValue);
1127                         Throws (field, instance, Int32Enum.MaxValue);
1128                         Throws (field, instance, UInt32Enum.MaxValue);
1129                         Throws (field, instance, Int64Enum.MaxValue);
1130                         Throws (field, instance, UInt64Enum.MaxValue);
1131                         field = fh.GetField ("field_UInt16Enum");
1132                         field.SetValue (instance, Byte.MaxValue);
1133                         Assert.AreEqual (Byte.MaxValue, (byte) instance.field_UInt16Enum);
1134                         Throws (field, instance, SByte.MaxValue);
1135                         Throws (field, instance, true);
1136                         field.SetValue (instance, Char.MaxValue);
1137                         Assert.AreEqual (Char.MaxValue, (char) instance.field_UInt16Enum);
1138                         Throws (field, instance, Int16.MaxValue);
1139                         field.SetValue (instance, UInt16.MaxValue);
1140                         Assert.AreEqual (UInt16.MaxValue, (UInt16) instance.field_UInt16Enum);
1141                         Throws (field, instance, Int32.MaxValue);
1142                         Throws (field, instance, UInt32.MaxValue);
1143                         Throws (field, instance, Int64.MaxValue);
1144                         Throws (field, instance, UInt64.MaxValue);
1145                         Throws (field, instance, Single.MaxValue);
1146                         Throws (field, instance, Double.MaxValue);
1147                         Throws (field, instance, IntPtr.Zero);
1148                         Throws (field, instance, UIntPtr.Zero);
1149                         Throws (field, instance, Decimal.MaxValue);
1150                         Throws (field, instance, DateTime.MaxValue);
1151                         field.SetValue (instance, ByteEnum.MaxValue);
1152                         Assert.AreEqual (ByteEnum.MaxValue, (ByteEnum) instance.field_UInt16Enum);
1153                         Throws (field, instance, SByteEnum.MaxValue);
1154                         Throws (field, instance, Int16Enum.MaxValue);
1155                         field.SetValue (instance, UInt16Enum.MaxValue);
1156                         Assert.AreEqual (UInt16Enum.MaxValue, instance.field_UInt16Enum);
1157                         Throws (field, instance, Int32Enum.MaxValue);
1158                         Throws (field, instance, UInt32Enum.MaxValue);
1159                         Throws (field, instance, Int64Enum.MaxValue);
1160                         Throws (field, instance, UInt64Enum.MaxValue);
1161                         field = fh.GetField ("field_Int32Enum");
1162                         field.SetValue (instance, Byte.MaxValue);
1163                         Assert.AreEqual (Byte.MaxValue, (byte) instance.field_Int32Enum);
1164                         field.SetValue (instance, SByte.MaxValue);
1165                         Assert.AreEqual (SByte.MaxValue, (sbyte) instance.field_Int32Enum);
1166                         Throws (field, instance, true);
1167                         field.SetValue (instance, Char.MaxValue);
1168                         Assert.AreEqual (Char.MaxValue, (char) instance.field_Int32Enum);
1169                         field.SetValue (instance, Int16.MaxValue);
1170                         Assert.AreEqual (Int16.MaxValue, (Int16) instance.field_Int32Enum);
1171                         field.SetValue (instance, UInt16.MaxValue);
1172                         Assert.AreEqual (UInt16.MaxValue, (UInt16) instance.field_Int32Enum);
1173                         field.SetValue (instance, Int32.MaxValue);
1174                         Assert.AreEqual (Int32.MaxValue, (Int32) instance.field_Int32Enum);
1175                         Throws (field, instance, UInt32.MaxValue);
1176                         Throws (field, instance, Int64.MaxValue);
1177                         Throws (field, instance, UInt64.MaxValue);
1178                         Throws (field, instance, Single.MaxValue);
1179                         Throws (field, instance, Double.MaxValue);
1180                         Throws (field, instance, IntPtr.Zero);
1181                         Throws (field, instance, UIntPtr.Zero);
1182                         Throws (field, instance, Decimal.MaxValue);
1183                         Throws (field, instance, DateTime.MaxValue);
1184                         field.SetValue (instance, ByteEnum.MaxValue);
1185                         Assert.AreEqual (ByteEnum.MaxValue, (ByteEnum) instance.field_Int32Enum);
1186                         field.SetValue (instance, SByteEnum.MaxValue);
1187                         Assert.AreEqual (SByteEnum.MaxValue, (SByteEnum) instance.field_Int32Enum);
1188                         field.SetValue (instance, Int16Enum.MaxValue);
1189                         Assert.AreEqual (Int16Enum.MaxValue, (Int16Enum) instance.field_Int32Enum);
1190                         field.SetValue (instance, UInt16Enum.MaxValue);
1191                         Assert.AreEqual (UInt16Enum.MaxValue, (UInt16Enum) instance.field_Int32Enum);
1192                         field.SetValue (instance, Int32Enum.MaxValue);
1193                         Assert.AreEqual (Int32Enum.MaxValue, instance.field_Int32Enum);
1194                         Throws (field, instance, UInt32Enum.MaxValue);
1195                         Throws (field, instance, Int64Enum.MaxValue);
1196                         Throws (field, instance, UInt64Enum.MaxValue);
1197                         field = fh.GetField ("field_UInt32Enum");
1198                         field.SetValue (instance, Byte.MaxValue);
1199                         Assert.AreEqual (Byte.MaxValue, (byte) instance.field_UInt32Enum);
1200                         Throws (field, instance, SByte.MaxValue);
1201                         Throws (field, instance, true);
1202                         field.SetValue (instance, Char.MaxValue);
1203                         Assert.AreEqual (Char.MaxValue, (char) instance.field_UInt32Enum);
1204                         Throws (field, instance, Int16.MaxValue);
1205                         field.SetValue (instance, UInt16.MaxValue);
1206                         Assert.AreEqual (UInt16.MaxValue, (UInt16) instance.field_UInt32Enum);
1207                         Throws (field, instance, Int32.MaxValue);
1208                         field.SetValue (instance, UInt32.MaxValue);
1209                         Assert.AreEqual (UInt32.MaxValue, (UInt32) instance.field_UInt32Enum);
1210                         Throws (field, instance, Int64.MaxValue);
1211                         Throws (field, instance, UInt64.MaxValue);
1212                         Throws (field, instance, Single.MaxValue);
1213                         Throws (field, instance, Double.MaxValue);
1214                         Throws (field, instance, IntPtr.Zero);
1215                         Throws (field, instance, UIntPtr.Zero);
1216                         Throws (field, instance, Decimal.MaxValue);
1217                         Throws (field, instance, DateTime.MaxValue);
1218                         field.SetValue (instance, ByteEnum.MaxValue);
1219                         Assert.AreEqual (ByteEnum.MaxValue, (ByteEnum) instance.field_UInt32Enum);
1220                         Throws (field, instance, SByteEnum.MaxValue);
1221                         Throws (field, instance, Int16Enum.MaxValue);
1222                         field.SetValue (instance, UInt16Enum.MaxValue);
1223                         Assert.AreEqual (UInt16Enum.MaxValue, (UInt16Enum) instance.field_UInt32Enum);
1224                         Throws (field, instance, Int32Enum.MaxValue);
1225                         field.SetValue (instance, UInt32Enum.MaxValue);
1226                         Assert.AreEqual (UInt32Enum.MaxValue, instance.field_UInt32Enum);
1227                         Throws (field, instance, Int64Enum.MaxValue);
1228                         Throws (field, instance, UInt64Enum.MaxValue);
1229                         field = fh.GetField ("field_Int64Enum");
1230                         field.SetValue (instance, Byte.MaxValue);
1231                         Assert.AreEqual (Byte.MaxValue, (byte) instance.field_Int64Enum);
1232                         field.SetValue (instance, SByte.MaxValue);
1233                         Assert.AreEqual (SByte.MaxValue, (sbyte) instance.field_Int64Enum);
1234                         Throws (field, instance, true);
1235                         field.SetValue (instance, Char.MaxValue);
1236                         Assert.AreEqual (Char.MaxValue, (char) instance.field_Int64Enum);
1237                         field.SetValue (instance, Int16.MaxValue);
1238                         Assert.AreEqual (Int16.MaxValue, (Int16) instance.field_Int64Enum);
1239                         field.SetValue (instance, UInt16.MaxValue);
1240                         Assert.AreEqual (UInt16.MaxValue, (UInt16) instance.field_Int64Enum);
1241                         field.SetValue (instance, Int32.MaxValue);
1242                         Assert.AreEqual (Int32.MaxValue, (Int32) instance.field_Int64Enum);
1243                         field.SetValue (instance, UInt32.MaxValue);
1244                         Assert.AreEqual (UInt32.MaxValue, (UInt32) instance.field_Int64Enum);
1245                         field.SetValue (instance, Int64.MaxValue);
1246                         Assert.AreEqual (Int64.MaxValue, (Int64) instance.field_Int64Enum);
1247                         Throws (field, instance, UInt64.MaxValue);
1248                         Throws (field, instance, Single.MaxValue);
1249                         Throws (field, instance, Double.MaxValue);
1250                         Throws (field, instance, IntPtr.Zero);
1251                         Throws (field, instance, UIntPtr.Zero);
1252                         Throws (field, instance, Decimal.MaxValue);
1253                         Throws (field, instance, DateTime.MaxValue);
1254                         field.SetValue (instance, ByteEnum.MaxValue);
1255                         Assert.AreEqual (ByteEnum.MaxValue, (ByteEnum) instance.field_Int64Enum);
1256                         field.SetValue (instance, SByteEnum.MaxValue);
1257                         Assert.AreEqual (SByteEnum.MaxValue, (SByteEnum) instance.field_Int64Enum);
1258                         field.SetValue (instance, Int16Enum.MaxValue);
1259                         Assert.AreEqual (Int16Enum.MaxValue, (Int16Enum) instance.field_Int64Enum);
1260                         field.SetValue (instance, UInt16Enum.MaxValue);
1261                         Assert.AreEqual (UInt16Enum.MaxValue, (UInt16Enum) instance.field_Int64Enum);
1262                         field.SetValue (instance, Int32Enum.MaxValue);
1263                         Assert.AreEqual (Int32Enum.MaxValue, (Int32Enum) instance.field_Int64Enum);
1264                         field.SetValue (instance, UInt32Enum.MaxValue);
1265                         Assert.AreEqual (UInt32Enum.MaxValue, (UInt32Enum) instance.field_Int64Enum);
1266                         field.SetValue (instance, Int64Enum.MaxValue);
1267                         Assert.AreEqual (Int64Enum.MaxValue, instance.field_Int64Enum);
1268                         Throws (field, instance, UInt64Enum.MaxValue);
1269                         field = fh.GetField ("field_UInt64Enum");
1270                         field.SetValue (instance, Byte.MaxValue);
1271                         Assert.AreEqual (Byte.MaxValue, (byte) instance.field_UInt64Enum);
1272                         Throws (field, instance, SByte.MaxValue);
1273                         Throws (field, instance, true);
1274                         field.SetValue (instance, Char.MaxValue);
1275                         Assert.AreEqual (Char.MaxValue, (char) instance.field_UInt64Enum);
1276                         Throws (field, instance, Int16.MaxValue);
1277                         field.SetValue (instance, UInt16.MaxValue);
1278                         Assert.AreEqual (UInt16.MaxValue, (UInt16) instance.field_UInt64Enum);
1279                         Throws (field, instance, Int32.MaxValue);
1280                         field.SetValue (instance, UInt32.MaxValue);
1281                         Assert.AreEqual (UInt32.MaxValue, (UInt32) instance.field_UInt64Enum);
1282                         Throws (field, instance, Int64.MaxValue);
1283                         field.SetValue (instance, UInt64.MaxValue);
1284                         Assert.AreEqual (UInt64.MaxValue, (UInt64) instance.field_UInt64Enum);
1285                         Throws (field, instance, Single.MaxValue);
1286                         Throws (field, instance, Double.MaxValue);
1287                         Throws (field, instance, IntPtr.Zero);
1288                         Throws (field, instance, UIntPtr.Zero);
1289                         Throws (field, instance, Decimal.MaxValue);
1290                         Throws (field, instance, DateTime.MaxValue);
1291                         field.SetValue (instance, ByteEnum.MaxValue);
1292                         Assert.AreEqual (ByteEnum.MaxValue, (ByteEnum) instance.field_UInt64Enum);
1293                         Throws (field, instance, SByteEnum.MaxValue);
1294                         Throws (field, instance, Int16Enum.MaxValue);
1295                         field.SetValue (instance, UInt16Enum.MaxValue);
1296                         Assert.AreEqual (UInt16Enum.MaxValue, (UInt16Enum) instance.field_UInt64Enum);
1297                         Throws (field, instance, Int32Enum.MaxValue);
1298                         field.SetValue (instance, UInt32Enum.MaxValue);
1299                         Assert.AreEqual (UInt32Enum.MaxValue, (UInt32Enum) instance.field_UInt64Enum);
1300                         Throws (field, instance, Int64Enum.MaxValue);
1301                         field.SetValue (instance, UInt64Enum.MaxValue);
1302                         Assert.AreEqual (UInt64Enum.MaxValue, instance.field_UInt64Enum);
1303
1304                 }
1305
1306                 static void Throws (FieldInfo field, object instance, object value)
1307                 {
1308                         try {
1309                                 field.SetValue (instance, value);
1310                                 Assert.Fail ("ArgumentException expected");
1311                         } catch (ArgumentException ex) {
1312                         }
1313                 }
1314
1315                 public object[] ObjectArrayField;
1316
1317                 [Test]
1318                 public void TestSetValueArray ()
1319                 {
1320                         var field = typeof (FieldInfoTest).GetField ("ObjectArrayField");
1321                         var instance = new FieldInfoTest ();
1322                         field.SetValue (instance, new string[] { "3" });
1323                         field.SetValue (instance, null);
1324
1325                         Throws (field, instance, new int[] { 3 });
1326                 }
1327
1328                 public IntEnum PPP;
1329
1330                 public class Foo<T>
1331                 {
1332                          /*
1333                         The whole point of this field is to make sure we don't create the vtable layout
1334                         when loading the value of constants for Foo<>. See bug #594942.
1335
1336                         */
1337                         public T dummy;
1338                         public static int field;
1339                         public const int constant = 10;
1340                         public const string sconstant = "waa";
1341                         public const IntEnum econstant = IntEnum.Third;
1342                 }
1343
1344                 public enum IntEnum {
1345                         First = 1,
1346                         Second = 2,
1347                         Third = 3
1348                 }
1349
1350                 public enum LongEnum : long {
1351                         First = 1,
1352                         Second = 2,
1353                         Third = 3
1354                 }
1355
1356                 public const int int_field = 5;
1357                 public const long long_field = Int64.MaxValue;
1358                 public const IntEnum int_enum_field = IntEnum.Second;
1359                 public const LongEnum long_enum_field = LongEnum.Second;
1360                 public const string string_field = "Hello";
1361                 public const FieldInfoTest object_field = null;
1362                 public int non_const_field;
1363
1364         }
1365
1366         // Helper classes
1367         class RefOnlyFieldClass 
1368         {
1369                 // Helper property
1370                 static int RefOnlyField;
1371         }
1372
1373         class NonPublicFieldClass
1374         {
1375                 protected int protectedField;
1376         }
1377
1378         public class FieldInfoTest<T>
1379         {
1380                 public T TestField;
1381         }
1382 }