예제 #1
0
        public void GraphRemoveCoexistents()
        {
            var A = new CircularEntity("A");
            var B = new CircularEntity("B");
            var C = new CircularEntity("C");
            var D = new CircularEntity("D");

            A = A + B + (C + D);

            var graphs = new List <Graph <CircularEntity> >
            {
                A.AsExpression(f => f.Children, e => e.Name).Graph,
                C.AsExpression(f => f.Children, e => e.Name).Graph
            };

            System.Console.WriteLine($"-> A: HashCode: {graphs[0].GetHashCode()}");
            foreach (Path <CircularEntity> path in graphs[0].Paths)
            {
                System.Console.WriteLine(path.ToString());
            }

            System.Console.WriteLine($"-> B: HashCode: {graphs[1].GetHashCode()}");
            foreach (Path <CircularEntity> path in graphs[1].Paths)
            {
                System.Console.WriteLine(path.ToString());
            }

            var graphsNonDuplicates = graphs.RemoveCoexistents();

            foreach (var graph in graphsNonDuplicates)
            {
                System.Console.WriteLine($"-> HashCode not duplicates: {graph.GetHashCode()}");
            }
        }
예제 #2
0
        public void GraphInfo()
        {
            var A = new CircularEntity("A");
            var B = new CircularEntity("B");
            var C = new CircularEntity("C");
            var D = new CircularEntity("D");

            A = A + B + (C + D);
            var expressionA = A.AsExpression(f => f.Children, e => e.Name);

            foreach (Edge <CircularEntity> edge in expressionA.Graph.Edges)
            {
                System.Console.WriteLine(edge.ToString());
            }

            foreach (Path <CircularEntity> path in expressionA.Graph.Paths)
            {
                System.Console.WriteLine(path.ToString());
            }

            foreach (EntityItem <CircularEntity> item in expressionA)
            {
                System.Console.WriteLine($"{item.ToString()} => {item.Path}");
            }
        }
예제 #3
0
        public void SerializationCircular1()
        {
            // create a simple object
            var A = new CircularEntity("A");
            var B = new CircularEntity("B");
            var C = new CircularEntity("C");
            var D = new CircularEntity("D");

            A = A + B + (C + D);

            var expression         = A.AsExpression(c => c.Children);
            var serialization      = new CircularEntityExpressionSerializer <CircularEntity>(expression, f => f.Name);
            var expressionAsString = serialization.Serialize();

            System.Console.WriteLine(expressionAsString);
        }
예제 #4
0
        public void SerializationCircular2()
        {
            // create a simple object
            var A = new CircularEntity("A");
            var B = new CircularEntity("B");
            var C = new CircularEntity("C");
            var D = new CircularEntity("BigName");

            A = A + B + (C + D);

            var expression    = A.AsExpression(c => c.Children);
            var serialization = new CircularEntityExpressionSerializer <CircularEntity>(expression, f => f.Name);

            serialization.EncloseParenthesisInRoot          = true;
            serialization.ForceQuoteEvenWhenValidIdentified = true;
            serialization.ValueFormatter = new TruncateFormatter(3);

            var expressionAsString = serialization.Serialize();

            System.Console.WriteLine(expressionAsString);
        }
예제 #5
0
        public void GraphCircular()
        {
            var A = new CircularEntity("A");
            var B = new CircularEntity("B");
            var C = new CircularEntity("C");
            var D = new CircularEntity("D");

            // ACTION: ADD
            A = A + B + (C + D);

            // PRINT 'A'
            Expression <CircularEntity> expression = A.AsExpression(e => e.Children, entityNameCallback: o => o.Name);

            foreach (EntityItem <CircularEntity> item in expression)
            {
                var ident  = new string(' ', item.Level * 2);
                var output = $"{ident}[{item.Index}] => Item: {item.Entity.Name}, Parent: {item.Parent?.Entity.Name}, Previous: {item.Previous?.Entity.Name}, Next: {item.Next?.Entity.Name}, Level: {item.Level}";
                System.Console.WriteLine(output);
            }

            System.Console.WriteLine(expression.DefaultSerializer.Serialize());


            // ACTION: REMOVE
            C = C - D;

            // PRINT 'A' AGAIN
            expression = A.AsExpression(e => e.Children, entityNameCallback: o => o.Name);
            foreach (EntityItem <CircularEntity> item in expression)
            {
                var ident  = new string(' ', item.Level * 2);
                var output = $"{ident}[{item.Index}] => Item: {item.Entity.Name}, Parent: {item.Parent?.Entity.Name}, Previous: {item.Previous?.Entity.Name}, Next: {item.Next?.Entity.Name}, Level: {item.Level}";
                System.Console.WriteLine(output);
            }

            // PRINT EXPRESSION
            System.Console.WriteLine(expression.DefaultSerializer.Serialize());
        }