在单元测试时,通过反射获取对象的属性值。
ToString
 1         private static string OutMessage(object lab)
 2         {
 3             Type t = lab.GetType();
 4             StringBuilder sb = new StringBuilder();
 5             foreach (var p in t.GetProperties())
 6             {
 7                 if (p.DeclaringType.Namespace == t.Namespace)
 8                 {
 9                     string value = p.GetValue(lab, null).ToString();
10                     if (string.IsNullOrEmpty(value))
11                         continue;
12 
13                     if (sb.Length > 0)
14                         sb.Append(",");
15                     sb.AppendFormat("{0}={1}", p.Name, p.GetValue(lab, null));
16                 }
17             }
18             return sb.ToString();
19         }

相关文章:

  • 2021-10-06
  • 2022-12-23
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-01
猜你喜欢
  • 2022-03-06
  • 2022-12-23
  • 2022-12-23
  • 2021-07-27
  • 2022-12-23
  • 2021-09-11
  • 2021-10-10
相关资源
相似解决方案