public void PosTest6() { genClass <int> str = new genClass <int>(12345); Type type = typeof(genClass <int>); FieldInfo fieldinfo = type.GetField("t"); object obj = fieldinfo.GetValue(str); Assert.Equal(12345, (int)obj); }
public void NegTest1() { genClass <int> str = new genClass <int>(12345); Type type = typeof(genClass <int>); FieldInfo fieldinfo = type.GetField("t"); // System.Reflection.TargetException not visible at the moment. Exception e = Assert.ThrowsAny <Exception>(() => fieldinfo.GetValue(null)); Assert.Equal("System.Reflection.TargetException", e.GetType().FullName); }
public void NegTest1() { try { genClass <int> str = new genClass <int>(12345); Type type = typeof(genClass <int>); FieldInfo fieldinfo = type.GetField("t"); object obj = fieldinfo.GetValue(null); Assert.True(false); } catch (Exception e) { if (e.GetType().ToString() != "System.Reflection.TargetException") { Assert.True(false); } } }