예제 #1
0
        public void LoggingExample()
        {
            var expression = OPathExpression.Compile("StringArray[0].Length > Int");

            var document = new OPathDocument {
                { "StringArray", new[] { "String" } }, { "Int", 0 }
            };

            var navigator = OPathNavigator.CreateNavigator(document);

            var result = navigator.Evaluate(expression, OPathOptions.Defaults, null, Console.WriteLine);

            Console.WriteLine(result);
        }
예제 #2
0
        public void HelloOPathNETExample()
        {
            var expression = OPathExpression.Compile("MyVariable = 'OPath.NET'");

            var document = new OPathDocument {
                { "MyVariable", "OPath.NET" }
            };

            var navigator = OPathNavigator.CreateNavigator(document);

            var result = navigator.Evaluate(expression);

            Console.WriteLine(result);
        }
예제 #3
0
        public void CustomFunctionExample()
        {
            var expression = OPathExpression.Compile("my-prefix:my-function(String, Int)");

            var document = new OPathDocument {
                { "String", "String" }, { "Int", 616 }
            };

            var navigator = OPathNavigator.CreateNavigator(document);

            navigator.RegisterCustomFunction("my-prefix", "my-function",
                                             args => string.Join(",", Array.ConvertAll(args, o => o + "")));

            var result = navigator.Evaluate(expression);

            Console.WriteLine(result);
        }
예제 #4
0
        public void TestOPathPerformance()
        {
            HiPerfTimer rawTimer = new HiPerfTimer();

            rawTimer.Start();

            for (int i = 0; i < EVALUATION_COUNT; i++)
            {
                OPathExpression opathExpression = OPathExpression.Compile(EXPRESSION);

                OPathDocument opathDocument = new OPathDocument();
                opathDocument.Add("listDictionary", m_ListDictionary);

                OPathNavigator opathNavigator = OPathNavigator.CreateNavigator(opathDocument);

                opathNavigator.Evaluate(opathExpression);
            }

            rawTimer.Stop();

            Console.WriteLine("Uncompiled OPath performance {0} evaluations in {1:0.000} millis",
                              EVALUATION_COUNT, (rawTimer.Duration * 1000));

            HiPerfTimer cachedTimer = new HiPerfTimer();

            cachedTimer.Start();

            OPathExpression cachedOPathExpression = OPathExpression.Compile(EXPRESSION);

            for (int i = 0; i < EVALUATION_COUNT; i++)
            {
                OPathDocument opathDocument = new OPathDocument();
                opathDocument.Add("listDictionary", m_ListDictionary);

                OPathNavigator opathNavigator = OPathNavigator.CreateNavigator(opathDocument);

                opathNavigator.Evaluate(cachedOPathExpression);
            }

            cachedTimer.Stop();

            Console.WriteLine("Compiled OPath performance {0} evaluations in {1:0.000} millis",
                              EVALUATION_COUNT, (cachedTimer.Duration * 1000));
        }
예제 #5
0
        public void OPathOptionsExample()
        {
            var expression = OPathExpression.Compile("MyVariable.Length = 0");

            var document = new OPathDocument {
                { "MyVariable", null }
            };

            var navigator = OPathNavigator.CreateNavigator(document);

            try
            {
                var result = navigator.Evaluate(expression);

                Console.WriteLine(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            try
            {
                var result = navigator.Evaluate(expression, OPathOptions.ReturnDefaultForNull);

                Console.WriteLine(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            try
            {
                var result = navigator.Evaluate(expression, OPathOptions.ReturnDefaultForNull, 0);

                Console.WriteLine(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }