public bool TryParse(string sourceText, out MarkupExtension graph)
        {
            graph = null;

            try
            {
                ParseTree tree = this.parser.Parse(sourceText);
#if DEBUG
                // Save result tree for debugging purposes.
                this.LastParseTree = tree;
                this.LastException = null;
#endif
                if (tree.Status == ParseTreeStatus.Parsed)
                {
                    graph = MarkupExtension.Create(tree.Root);
                    return(true);
                }
            }
#if DEBUG
            catch (Exception ex)
            {
                this.LastParseTree = null;
                this.LastException = ex;
            }
#else
            catch
            {
                // ignored
            }
#endif
            return(false);
        }
 /// <summary>
 /// Format markup extension and return elements as formatted lines with "local" indention.
 /// Indention from previous element/attribute/tags must be applied separately
 /// </summary>
 /// <param name="markupExtension"></param>
 /// <returns></returns>
 public IEnumerable<string> Format(MarkupExtension markupExtension)
 {
     var formatter = (this.singleLineTypes.Contains(markupExtension.TypeName))
         ? this.singleLineFormatter
         : this.multiLineFormatter;
     return formatter.Format(markupExtension);
 }
Esempio n. 3
0
        public bool TryParse(string sourceText, out MarkupExtension graph)
        {
            graph = null;

            try
            {
                ParseTree tree = this.parser.Parse(sourceText);
#if DEBUG
                // Save result tree for debugging purposes.
                this.LastParseTree = tree;
                this.LastException = null;
#endif
                if (tree.Status == ParseTreeStatus.Parsed)
                {
                    graph = MarkupExtension.Create(tree.Root);
                    return true;
                }
            }
#if DEBUG
            catch (Exception ex)
            {
                this.LastParseTree = null;
                this.LastException = ex;
            }
#else
            catch
            {
                // ignored
            }
#endif
            return false;
        }
Esempio n. 4
0
 public AttributeInfo(string name, string value, AttributeOrderRule orderRule, MarkupExtension markupExtension)
 {
     this.Name = name;
     this.Value = value;
     this.OrderRule = orderRule;
     this.MarkupExtension = markupExtension;
 }
        public void TestSignificantSpacing()
        {
            var sourceText = @"  { Binding  StringFormat = {} {0}\  , Mode = OneWay } ";
            var expected = new MarkupExtension(
                "Binding",
                new NamedArgument("StringFormat", @"{} {0}\ "),
                new NamedArgument("Mode", "OneWay"));

            this.ParseAndAssertObjectGraph(sourceText, expected);
        }
        public void TestHelloworldFoo1Bar42_spaced()
        {
            var sourceText = "  {  Hello   world ,  foo  =  1  ,  bar = 42  }  ";
            var expected = new MarkupExtension(
                "Hello",
                new PositionalArgument("world"),
                new NamedArgument("foo", "1"),
                new NamedArgument("bar", "42"));

            this.ParseAndAssertObjectGraph(sourceText, expected);
        }
        public void TestBindingHelloFooBar()
        {
            var sourceText = "{Binding Hello, foo,bar}";
            var expected = new MarkupExtension(
                "Binding",
                new PositionalArgument("Hello"),
                new PositionalArgument("foo"),
                new PositionalArgument("bar"));

            this.ParseAndAssertObjectGraph(sourceText, expected);
        }
Esempio n. 8
0
        private static IEnumerable <Argument> GetArguments(IEnumerable <ParseTreeNode> nodes)
        {
            foreach (var node in nodes)
            {
                var argument = PositionalArgument.Create(node) ?? (Argument)NamedArgument.Create(node);

                if (argument != null)
                {
                    yield return(argument);
                }
                else
                {
                    // Unwrap argument.
                    foreach (var markupExtensionArgument in MarkupExtension.GetArguments(node.ChildNodes))
                    {
                        yield return(markupExtensionArgument);
                    }
                }
            }
        }
        public void TestNestedBinding()
        {
            var sourceText = "{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type gpc:MainWindow}}}";
            var expected = new MarkupExtension(
                "Binding",
                new PositionalArgument("ActualHeight"),
                new NamedArgument("Mode", "OneWay"),
                new NamedArgument(
                    "RelativeSource",
                    new MarkupExtension(
                        "RelativeSource",
                        new PositionalArgument("FindAncestor"),
                        new NamedArgument(
                            "AncestorType",
                            new MarkupExtension("x:Type", new PositionalArgument("gpc:MainWindow"))))));

            this.ParseAndAssertObjectGraph(sourceText, expected);
        }
        private void ParseAndAssertObjectGraph(string sourceText, MarkupExtension expected)
        {
            IMarkupExtensionParser markupExtensionParser = new MarkupExtensionParser();
            MarkupExtension actual;
            var result = markupExtensionParser.TryParse(sourceText, out actual);

            Assert.That(result, Is.True);
            Assert.That(actual, Is.Not.Null);

            var compareLogic = new CompareLogic();
            var compareResult = compareLogic.Compare(expected, actual);
            Assert.That(compareResult.AreEqual, Is.True, compareResult.DifferencesString);
        }
        public void TestEscapedBraces2()
        {
            var sourceText = @"{Binding Value, StringFormat={}{0:N2}}";
            var expected = new MarkupExtension(
                "Binding",
                new PositionalArgument("Value"),
                new NamedArgument("StringFormat", "{}{0:N2}"));

            this.ParseAndAssertObjectGraph(sourceText, expected);
        }
        public void TestNestedBindingWithBraceFormat()
        {
            var sourceText = @"{Binding Title,
                              RelativeSource={RelativeSource FindAncestor,
                                                             AncestorType={x:Type UserControl}},
                              StringFormat={}{0}Now{{0}} - {0}}";
            var expected = new MarkupExtension(
                "Binding",
                new PositionalArgument("Title"),
                new NamedArgument(
                    "RelativeSource",
                    new MarkupExtension(
                        "RelativeSource",
                        new PositionalArgument("FindAncestor"),
                        new NamedArgument(
                            "AncestorType",
                            new MarkupExtension("x:Type", new PositionalArgument("UserControl"))))),
                new NamedArgument("StringFormat", "{}{0}Now{{0}} - {0}"));

            this.ParseAndAssertObjectGraph(sourceText, expected);
        }
 public void TestHello()
 {
     var sourceText = "{Hello}";
     var expected = new MarkupExtension("Hello");
     this.ParseAndAssertObjectGraph(sourceText, expected);
 }
        public void TestNestedBinding2()
        {
            var sourceText = @"{DynamicResource {x:Static SystemColors.ControlTextBrushKey},
                                       ResourceKey={x:Static SystemColors.ControlTextBrushKey}}";
            var expected = new MarkupExtension(
                "DynamicResource",
                new PositionalArgument(new MarkupExtension(
                    "x:Static",
                    new PositionalArgument("SystemColors.ControlTextBrushKey"))),
                new NamedArgument(
                    "ResourceKey",
                    new MarkupExtension(
                        "x:Static", 
                        new PositionalArgument("SystemColors.ControlTextBrushKey"))));

            this.ParseAndAssertObjectGraph(sourceText, expected);
        }
 public IEnumerable<string> Format(MarkupExtension markupExtension)
 {
     return markupExtension.Arguments.Any()
         ? this.Format($"{{{markupExtension.TypeName} ", this.Format(markupExtension.Arguments), "}")
         : new string[] { $"{{{markupExtension.TypeName}}}" };
 }
Esempio n. 16
0
 /// <summary>
 /// Format markup extension on a single line.
 /// </summary>
 /// <param name="markupExtension"></param>
 /// <returns></returns>
 public string FormatSingleLine(MarkupExtension markupExtension)
 {
     return this.singleLineFormatter.Format(markupExtension).Single();
 }
 public void TestHelloWorld42()
 {
     var sourceText = "{Hello world=42}";
     var expected = new MarkupExtension("Hello", new NamedArgument("world", "42"));
     this.ParseAndAssertObjectGraph(sourceText, expected);
 }
Esempio n. 18
0
 public static Value Create(ParseTreeNode node)
 {
     return(LiteralValue.Create(node) ?? (Value)MarkupExtension.Create(node));
 }