Assert.IsNull (ex.ParamName, "#5");
}
}
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void GetFieldFromHandle2_Incompatible ()
+ {
+ RuntimeFieldHandle fh = typeof (FieldInfoTest<int>).GetField ("TestField").FieldHandle;
+
+ FieldInfoTest<string> instance = new FieldInfoTest<string> ();
+ Type t2 = instance.GetType ();
+ RuntimeTypeHandle th = t2.TypeHandle;
+
+ FieldInfo fi2 = FieldInfo.GetFieldFromHandle (fh, th);
+ }
#endif
[Test]
// get it for real
fi = t.GetField ("protectedField", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.IsNotNull (fi);
- // get via typebuilder
- FieldInfo f = TypeBuilder.GetField (t, fi);
- Assert.IsNotNull (f);
}
#endif // TARGET_JVM
typeof (FieldInfoTest).GetField ("non_const_field").GetRawConstantValue ();
}
-#if NET_2_0
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void GetValueOpenGeneric ()
public void GetValueOnConstantOfOpenGeneric ()
{
Assert.AreEqual (10, typeof(Foo<>).GetField ("constant").GetValue (null), "#1");
+ Assert.AreEqual ("waa", typeof(Foo<>).GetField ("sconstant").GetValue (null), "#2");
+ Assert.AreEqual (IntEnum.Third, typeof(Foo<>).GetField ("econstant").GetValue (null), "#3");
}
public class Foo<T>
{
+ /*
+ The whole point of this field is to make sure we don't create the vtable layout
+ when loading the value of constants for Foo<>. See bug #594942.
+
+ */
+ public T dummy;
public static int field;
public const int constant = 10;
+ public const string sconstant = "waa";
+ public const IntEnum econstant = IntEnum.Third;
}
-#endif
public enum IntEnum {
First = 1,