f.SetValue (null, 8);
}
+ const int literal = 42;
+
+ [Test]
+ [ExpectedException (typeof (FieldAccessException))]
+ public void SetValueOnLiteralField ()
+ {
+ FieldInfo f = typeof (FieldInfoTest).GetField ("literal", BindingFlags.Static | BindingFlags.NonPublic);
+ f.SetValue (null, 0);
+ }
+
public int? nullable_field;
public static int? static_nullable_field;
- public string? nullable_reference_field;
-
[Test]
public void NullableTests ()
{
AssertEquals (101, fi2.GetValue (t));
fi2.SetValue (t, null);
AssertEquals (null, fi2.GetValue (t));
-
- FieldInfo fi3 = typeof (FieldInfoTest).GetField ("nullable_reference_field");
-
- fi3.SetValue (t, "ABC");
- AssertEquals ("ABC", fi3.GetValue (t));
- fi3.SetValue (t, null);
- AssertEquals (null, fi3.GetValue (t));
}
#endif
}