关于返回值为引用类型的函数,如何用Assert进行判断,特别是集合内是引用类型的(多层引用类型嵌套,如A集合内是B引用类型元素,而B内又有C和D等引用类型成员,etc),这各情况怎么处理?

解决方案 »

  1.   

    我是这样做的:分解引用类型成最终的细小值类型,再进行分别的Assert,不知有没有其它比较好的方法
      

  2.   


            public static void Check(T Object1, T Object2)
            {
                Type t = typeof(T);
                PropertyInfo[] pros = t.GetProperties();
                foreach (PropertyInfo pro in pros)
                {
                    string str1 = pro.GetValue(Object1, null).ToString();
                    string str2 = pro.GetValue(Object2, null).ToString();
                    Assert.AreEqual(str1, str2, "error");
                }
            }