private static IRawTree[] GetChildrenByProperties(IPgNode tree) { return(tree.GetType().GetProperties() .Select(pi => (pi, pi.GetValue(tree))) .Where(x => x.Item2 != null && x.pi.PropertyType != typeof(NodeTag)) .Select(x => { var(pi, value) = x; IRawTree rawTree; if (typeof(IPgNode).IsAssignableFrom(pi.PropertyType)) { rawTree = new PostgreSqlRawTree((IPgNode)value); } else if (typeof(IPgNode[]).IsAssignableFrom(pi.PropertyType)) { rawTree = new PostgreSqlRawTree(pi.Name, (IPgNode[])value); } else { rawTree = new PostgreSqlRawTree(pi.Name, value); } return rawTree; }) .ToArray()); }
internal PostgreSqlRawTree(IPgNode tree) { DisplayName = tree.GetType().Name; Children = GetChildrenByProperties(tree); }