コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: FieldInfoGetValue1.cs プロジェクト: wpsmith/corefx
 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);
         }
     }
 }