Exemplo n.º 1
0
 private static XNamespace[] FindNamespaces(DynamicXmlBuilder builder)
 {
     XDocument xDocument = builder.ToXDocument();
       var namespaces = xDocument.Root
                         .DescendantsAndSelf()
                         .Select(x => x.Name.Namespace)
                         .Distinct()
                         .ToArray();
       return namespaces;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Alternate syntax for generating an XML object via this static factory
        /// method instead of expliclty creating a "dynamic" in client code.
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static DynamicXmlBuilder Build(Action <dynamic> builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            var xbuilder = new DynamicXmlBuilder();

            builder(xbuilder);
            return(xbuilder);
        }
Exemplo n.º 3
0
        public void Tag_Not_Writes_Blank_XmlNamespaces()
        {
            const string xmlns = "http://foo.com";

              dynamic builder = new DynamicXmlBuilder();
              builder.Foo(new { xmlns = xmlns }, DynamicXmlBuilder.Fragment(x =>
            x.Bar("foobar")
              ));

              var namespaces = FindNamespaces(builder);

              Assert.Equal(1, namespaces.Length);
              Assert.Equal(xmlns, namespaces[0]);
        }
Exemplo n.º 4
0
        public void Tag_Adds_Nested_XmlNamespace_Properly()
        {
            const string xmlns = "http://foo.com";
              const string xmlns2 = "http://foobar.com";

              dynamic builder = new DynamicXmlBuilder();
              builder.Foo(new { xmlns = xmlns }, DynamicXmlBuilder.Fragment(x =>
            x.Bar("foobar", new { xmlns = xmlns2 })
              ));

              var namespaces = FindNamespaces(builder);

              Assert.Equal(2, namespaces.Length);
              Assert.Equal(xmlns, namespaces[0]);
              Assert.Equal(xmlns2, namespaces[1]);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Alternate syntax for generating an XML object via this static factory
        /// method instead of expliclty creating a "dynamic" in client code.
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static DynamicXmlBuilder Build(Action<dynamic> builder)
        {
            if (builder == null) { throw new ArgumentNullException("builder"); }

              var xbuilder = new DynamicXmlBuilder();
              builder(xbuilder);
              return xbuilder;
        }