Пример #1
0
        public static Dictionary <string, object> ToDictionary(object target)
        {
            Dictionary <string, object> result2;

            if (null == target)
            {
                result2 = null;
            }
            else
            {
                if (target is Dictionary <string, object> )
                {
                    result2 = (target as Dictionary <string, object>);
                }
                else
                {
                    if (target is KeyValuePair <string, object> )
                    {
                        KeyValuePair <string, object> kvp = (KeyValuePair <string, object>)target;
                        result2 = new Dictionary <string, object>
                        {
                            {
                                kvp.Key,
                                kvp.Value
                            }
                        };
                    }
                    else
                    {
                        if (target is DataRowView)
                        {
                            result2 = ReflectionServices.ToDictionary((DataRowView)target);
                        }
                        else
                        {
                            if (target is DataRow)
                            {
                                result2 = ReflectionServices.ToDictionary((DataRow)target);
                            }
                            else
                            {
                                if (target is IList)
                                {
                                    result2 = ReflectionServices.ToDictionary((IList)target);
                                }
                                else
                                {
                                    if (target is IDictionary)
                                    {
                                        result2 = ReflectionServices.ToDictionary((IDictionary)target);
                                    }
                                    else
                                    {
                                        if (target is IDataRecord)
                                        {
                                            result2 = ReflectionServices.ToDictionary((IDataRecord)target);
                                        }
                                        else
                                        {
                                            if (target is IHierarchyData)
                                            {
                                                result2 = ToDictionary((IHierarchyData)target);
                                            }
                                            else
                                            {
                                                Dictionary <string, object> result3 = new Dictionary <string, object>();
                                                PropertyInfo[] properties           = target.GetType().GetProperties();
                                                for (int i = 0; i < properties.Length; i++)
                                                {
                                                    PropertyInfo propertyInfo = properties[i];
                                                    if (0 == propertyInfo.GetIndexParameters().Length)
                                                    {
                                                        result3.Add(propertyInfo.Name, propertyInfo.GetValue(target, null));
                                                    }
                                                }
                                                result2 = result3;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(result2);
        }
Пример #2
0
 public static Dictionary <string, object> ToDictionary(DataRowView target)
 {
     return(ReflectionServices.ToDictionary(target.Row));
 }