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;
            }
    
  • 相关阅读:
    C#字符串(截取)
    字符串的截取(从指定位置)
    UVALive 7146 Defeat the Enemy(贪心+STL)(2014 Asia Shanghai Regional Contest)
    UVALive 7148 LRIP(树的分治+STL)(2014 Asia Shanghai Regional Contest)
    Google Code Jam Round 1A 2015 解题报告
    编程之美2015资格赛 解题报告
    ZOJ 3781 Paint the Grid Reloaded(BFS)
    【转】赞一下huicpc035
    【转】lonekight@xmu·ACM/ICPC 回忆录
    【转】[退役]纪念我的ACM——headacher@XDU
  • 原文地址:https://www.cnblogs.com/futao/p/2803493.html
Copyright © 2011-2022 走看看