zoukankan      html  css  js  c++  java
  • C# 并行 反射 去掉实体属性多余空格

     

        有时会遇到很多不合理的数据附件到实体后有大量空格需要处理,这里提供一个方法,通过并行反射的方式高效清理空格。

     

    Code:

    1. //清除字符串空格
    2. public static object TrimString(object obj)
    3. {
    4.     try
    5.     {
    6.         Type t = obj.GetType();
    7.         PropertyInfo[] props = t.GetProperties();
    8.  
    9.         Parallel.ForEach(props, p =>
    10.         {
    11.             if (p.PropertyType.Name == "String")
    12.             {
    13.                 var tmp = (string)p.GetValue(obj, null);
    14.                 p.SetValue(obj, tmp.Trim(), null);
    15.             }
    16.         });
    17.  
    18.         return obj;
    19.     }
    20.     catch
    21.     {
    22.         return obj;
    23.     }
    24. }
  • 相关阅读:
    表值函数,标量值函数
    考勤率
    精确小数点
    SQL 返回刚插入的值
    xml读取
    备份表
    case,cast
    DDR基础知识
    NXP官方的I.MX6UL板级Uboot源码适配
    高通msm8909打开debug串口
  • 原文地址:https://www.cnblogs.com/long-gengyun/p/3410023.html
Copyright © 2011-2022 走看看