设置实体类型中String类型的属性值为String.Empty

 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         }
原文地址:https://www.cnblogs.com/yanglang/p/6867533.html