示例#1
0
        /// <summary>
        /// for a given node returns all the child nodes
        /// </summary>
        /// <param name="nodeValue"></param>
        /// <param name="parentNodePath"></param>
        /// <returns></returns>
        public static List <Tuple <object, GraphPath> > GetChildTraversalNodes(object nodeValue, GraphPath parentNodePath,
                                                                               Func <object, GraphPath, bool> doNotTraverseFilter = null)
        {
            List <Tuple <object, GraphPath> > rv = new List <Tuple <object, GraphPath> >();

            //if the node is IEnumerable, recurse here
            if (nodeValue is IEnumerable && (nodeValue is string) == false)
            {
                IEnumerable objEnumerable = nodeValue as IEnumerable;

                int index = 0;
                foreach (var each in objEnumerable)
                {
                    //build the path
                    var path = GraphPath.New(parentNodePath);
                    path.AddSegment(EnumeratedItemSegment.New(index));

                    if (doNotTraverseFilter != null &&
                        doNotTraverseFilter(each, path))
                    {
                        continue;
                    }

                    rv.Add(new Tuple <object, GraphPath>(each, path));
                    index++;
                }
            }
            else
            {
                //recurse the fields
                var fields = GraphingUtil.GetNestingNotatedFieldInfos(nodeValue.GetType());

                foreach (var field in fields)
                {
                    //get field value
                    var obj = field.Item2.GetValue(nodeValue);

                    var path = GraphPath.New(parentNodePath);
                    path.AddSegment(GraphSegment.New(field.Item1));

                    if (doNotTraverseFilter != null &&
                        doNotTraverseFilter(obj, path))
                    {
                        continue;
                    }

                    //build the node and recurse
                    rv.Add(new Tuple <object, GraphPath>(obj, path));
                }
            }
            return(rv);
        }
示例#2
0
        /// <summary>
        /// given the object to graph, builds a graph
        /// </summary>
        /// <param name="obj"></param>
        private void BuildGraph(object obj, Func <object, GraphPath, bool> skipFilter = null)
        {
            /*
             *  We walk each object in the graph and convert that into a GraphNode (ie. GraphPath + ManagedValue + Sequence)
             *
             */

            Condition.Requires(obj).IsNotNull();

            this.NodeStore  = NaturalInMemoryStore.New().IsOf <GraphNode>();
            this.Counter    = new Counter();
            this.SkipFilter = skipFilter;

            var rootPath = GraphPath.New();

            //build the node and recurse, maybe
            BuildNode(obj, rootPath);
        }
示例#3
0
 public static GraphNode GetRootNode(this IStoreOf <GraphNode> nodeStore)
 {
     return(GetNode(nodeStore, GraphPath.New()));
 }