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;
            }
    
  • 相关阅读:
    亚马逊产品图片爬取
    页面浏览统计之(一) hitcount
    页面浏览统计之(二) tracking
    页面浏览统计之(三) tracking2
    Django CMS apphooks – 使用应用钩子来添加主题应用
    Django CMS 插件 – 添加博客专题
    [整理] Windows下打印网页
    CompletableFuture详解
    详解JVM常量池、Class、运行时、字符串常量池
    分库分表总结
  • 原文地址:https://www.cnblogs.com/futao/p/2803493.html
Copyright © 2011-2022 走看看