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

 1      /// 
 2         ///  将String类型的属性值设置为String.Empty
 3         /// 
 4         /// 强类型Entity
 5         /// 
 6         public static void DefaultStringProperty(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/joryblog/p/6867384.html

你可能感兴趣的:(设置实体类型中String类型的属性值为String.Empty)