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;
            }
    
  • 相关阅读:
    [COI2007] Patrik 音乐会的等待 单调栈
    [NOI2012]随机数生成器 矩阵乘法
    流程控制主while,for,python画金字塔,画9*9乘法表
    VS第一天(一堆错误的错误示范)
    markdown插入表格语法
    格式化输出,基本运算符,流程控制主if
    jupyter notebook的插件安装及文本格式修改
    7个好用的社交分享按钮代码片段
    标签页tab.js 在栏目之间切换,局部变化
    详解 CSS 属性
  • 原文地址:https://www.cnblogs.com/futao/p/2803493.html
Copyright © 2011-2022 走看看