Esempio n. 1
0
        internal static IEnumerable <HierarchyPropertyNode> BuildPropertyList(this Type baseType, bool ExpandNonPrimitiveClass = false, ExpandPropertyOptions expandPropertyOptions = null, HierarchyPropertyNode parent = null)
        {
            if (expandPropertyOptions == null)
            {
                expandPropertyOptions = new ExpandPropertyOptions();
            }
            PropertyInfo[] properties        = baseType.GetProperties();
            List <HierarchyPropertyNode> res = new List <HierarchyPropertyNode>();

            PropertyInfo[] array = properties;
            foreach (PropertyInfo prop in array)
            {
                HierarchyPropertyNode hpn = new HierarchyPropertyNode
                {
                    parent   = parent,
                    Property = prop
                };
                res.Add(hpn);
                if (ExpandNonPrimitiveClass && prop.PropertyType.CanExpand() && expandPropertyOptions.CanExpand(hpn))
                {
                    res.AddRange(prop.PropertyType.BuildPropertyList(ExpandNonPrimitiveClass, expandPropertyOptions, hpn));
                }
            }
            return(res);
        }
Esempio n. 2
0
        public static DataTable ToDataTable <T>(this IEnumerable <T> datas, bool ExpandNonPrimitiveClass = false, ExpandPropertyOptions expandPropertyOptions = null)
        {
            Type baseType = typeof(T);
            IEnumerable <HierarchyPropertyNode> hlist = baseType.BuildPropertyList(ExpandNonPrimitiveClass);
            DataTable res = new DataTable();

            foreach (HierarchyPropertyNode prop2 in hlist.Where((HierarchyPropertyNode x) => !hlist.Any((HierarchyPropertyNode y) => y.parent == x)))
            {
                res.Columns.Add(new DataColumn
                {
                    ColumnName = prop2.PropertyName,
                    DataType   = NonNullable(prop2.Property.PropertyType)
                });
            }
            foreach (T data in datas)
            {
                DataRow row = res.NewRow();
                foreach (HierarchyPropertyNode prop in hlist.Where((HierarchyPropertyNode x) => !hlist.Any((HierarchyPropertyNode y) => y.parent == x)))
                {
                    object d = prop.GetHierarchicalValue(data);
                    if (d != null)
                    {
                        row[prop.PropertyName] = d;
                    }
                }
                res.Rows.Add(row);
            }
            return(res);
        }
Esempio n. 3
0
 public static DataTable ToDataTable <T>(this IEnumerable <T> datas, ExpandPropertyOptions expandPropertyOptions = null)
 {
     return(datas.ToDataTable(expandPropertyOptions != null, expandPropertyOptions));
 }