zoukankan      html  css  js  c++  java
  • 一段反射的代码

            public static bool IsLegitimateDic(object o, DataSet dicDS, out string logContent)
            {
                bool isError = false;
                logContent = string.Empty;
                PropertyInfo[] properties = o.GetType().GetProperties();
                string filter = string.Empty;
                string propName = string.Empty;
                try
                {
                    foreach (PropertyInfo item in properties)
                    {
                        propName = item.Name;
                        if (item.GetValue(o, null) != null)
                        {
                            string value = item.GetValue(o, null).ToString();
                            if (string.IsNullOrEmpty(value))
                                continue;
                            if (dicEnum == null)
                                isLegitimate();
                            if (dicEnum.ContainsKey(propName))
                            {
                                string tableName = dicEnum[propName];
                                filter = string.Empty;
                                switch (tableName)
                                {
                                    case "RME_CarSeries":
                                        filter = "Key = " + value + " and ParentsCode = " + o.GetType().GetProperty("IntendedBrand").GetValue(o, null);
                                        break;
    
                                    //case "RME_CarSeries2":
                                    //    dicDS.Tables[tableName].DefaultView.RowFilter = "Key = " + value + " and ParentsCode = " + o.GetType().GetProperty("IntendedBrand").GetValue(o, null);
                                    //    break;
    
                                    case "RME_City":
                                        filter = "Key = " + value + " and ParentsCode = " + o.GetType().GetProperty("Province").GetValue(o, null);
                                        break;
                                    case "RME_CarModel":
                                        filter = "ModelValue = " + value + " and ClassValue = " + o.GetType().GetProperty("IntendedClass").GetValue(o, null);
                                        break;
                                    case "RME_Campaign":
                                        value = value.Replace(',', ',');
                                        string[] ids = value.Split(',');
                                        filter = "Key = " + ids[0];
                                        for (int i = 1; i < ids.Count(); i++)
                                        {
                                            filter += " or Key = " + ids[i];
                                        }
                                        break;
                                    default:
                                        filter = "Key = " + value;
                                        break;
                                }
                                dicDS.Tables[tableName].DefaultView.RowFilter = filter;
    
                                if (dicDS.Tables[tableName].DefaultView.Count == 0)
                                {
                                    isError = true;
                                    logContent += "[" + propName + "=" + value.ToString() + "(" + filter + ")]";
                                }
                                //清空过滤条件
                                dicDS.Tables[tableName].DefaultView.RowFilter = "";
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    isError = true;
                    logContent += "[(filter=" + filter + ")(propName=" + propName + ")]";
                }
    
                return isError;
            }
    
  • 相关阅读:
    ckplayer的Error #2033:Can not call javascript:ckstyle()解决
    C#中的参数关键字params
    c#中的可选参数和命名参数的使用
    c#中的dynamic类型
    c#中关于变量声明那么点事
    C# 自定义控件的一些文章和博客
    datatable,查询,排序,复制等操作
    HTML5 实现图像模糊算法
    FASTCGI程序,做个备份,以后用
    PHP的一些函数
  • 原文地址:https://www.cnblogs.com/futao/p/2803493.html
Copyright © 2011-2022 走看看