runliuv

runliuv@cnblogs

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 

--

 

System.Reflection.PropertyInfo[] cfgItemProperties = cfgItem.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
                    SortedDictionary<string, string> sdCfgItem = new SortedDictionary<string, string>();
                    foreach (System.Reflection.PropertyInfo item in cfgItemProperties)
                    {
                        string name = item.Name;
                        object value = item.GetValue(cfgItem, null);
                        if (value != null && (item.PropertyType.IsValueType || item.PropertyType.Name.StartsWith("String")) && !string.IsNullOrWhiteSpace(value.ToString()))
                        {
                            sdCfgItem.Add(name, value.ToString());
                        }
                    }

 

--

cfgItem 是实体类。

自己可以封装为公共方法。

 

posted on 2019-04-22 16:32  runliuv  阅读(1176)  评论(0编辑  收藏  举报