1      /// <summary>
 2         ///  将String类型的属性值设置为String.Empty
 3         /// </summary>
 4         /// <typeparam name="T">强类型Entity</typeparam>
 5         /// <param name="result"></param>
 6         public static void DefaultStringProperty<T>(T result) where T : class
 7         {
 8             Type t = typeof(T);
 9             System.Reflection.PropertyInfo[] propertyInfos = t.GetProperties();
10             foreach (PropertyInfo pi in propertyInfos)
11             {
12                 if (pi.PropertyType.Equals(typeof(string)))
13                 {
14                     object _origanlValue = pi.GetValue(result, null);
15                     if (_origanlValue == null)
16                     {
17                         pi.SetValue(result, string.Empty, null);
18                     }
19                 }
20             }
21         }

 

相关文章:

  • 2022-12-23
  • 2021-07-26
  • 2021-11-22
  • 2022-02-09
  • 2021-05-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2022-01-28
  • 2021-11-10
  • 2022-02-11
相关资源
相似解决方案