コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the DynaXmlBuilder class.
 /// </summary>
 /// <param name="document">
 /// The XmlDocument to use for building.
 /// </param>
 /// <param name="includeHeader">
 /// A flag indicating that a header should be included.
 /// </param>
 /// <param name="xmlFormatting">
 /// The XmlFormatting style to use when writing the document.
 /// </param>
 internal DynaXmlBuilder(DynaXmlDocument document, bool includeHeader, Formatting xmlFormatting)
 {
     this.xmlFormatting = xmlFormatting;
     this.includeHeader = includeHeader;
     this.context       = new DynaXmlBuilderContext();
     this.document      = document;
     // this.context.Push(this.document, DynaXmlBuilderState.ElementBuilder);
     this.context.Push(this.document, DynaXmlBuilderState.ElementListBuilder);
 }
コード例 #2
0
        /// <summary>
        ///     Initializes a new instance of the DynaXmlBuilderContext class.
        /// </summary>
        /// <param name="original">Original context.</param>
        public DynaXmlBuilderContext(DynaXmlBuilderContext original)
        {
            if (original == null)
            {
                throw new ArgumentNullException("original");
            }

            IEnumerable<DynaXmlContextState> list = new List<DynaXmlContextState>(original.stack);
            IEnumerable<DynaXmlContextState> reversed = list.Reverse();
            this.stack = new Stack<DynaXmlContextState>(reversed);
        }
コード例 #3
0
        /// <summary>
        ///     Initializes a new instance of the DynaXmlBuilderContext class.
        /// </summary>
        /// <param name="original">Original context.</param>
        public DynaXmlBuilderContext(DynaXmlBuilderContext original)
        {
            if (original == null)
            {
                throw new ArgumentNullException("original");
            }

            IEnumerable <DynaXmlContextState> list     = new List <DynaXmlContextState>(original.stack);
            IEnumerable <DynaXmlContextState> reversed = list.Reverse();

            this.stack = new Stack <DynaXmlContextState>(reversed);
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the DynaXmlBuilder class.
 /// </summary>
 /// <param name="document">
 /// The XmlDocument to use for building.
 /// </param>
 /// <param name="includeHeader">
 /// A flag indicating that a header should be included.
 /// </param>
 /// <param name="xmlFormatting">
 /// The XmlFormatting style to use when writing the document.
 /// </param>
 internal DynaXmlBuilder(DynaXmlDocument document, bool includeHeader, Formatting xmlFormatting)
 {
     this.xmlFormatting = xmlFormatting;
     this.includeHeader = includeHeader;
     this.context = new DynaXmlBuilderContext();
     this.document = document;
     // this.context.Push(this.document, DynaXmlBuilderState.ElementBuilder);
     this.context.Push(this.document, DynaXmlBuilderState.ElementListBuilder);
 }
コード例 #5
0
        /// <inheritdoc />
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            // For interface flowing, the resulting object is always this object.
            result = this;
            if (binder == null)
            {
                throw new ArgumentNullException("binder");
            }

            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            // Ends the line of chaining.
            if (binder.Name == "End" && !this.IsLiteratState)
            {
                return true;
            }

            if (args.Length == 0 || args[0].IsNull())
            {
                if (this.IsElementState)
                {
                    this.ElementBuilderInvokeMember(binder.Name, string.Empty);
                }
                throw new ArgumentOutOfRangeException("args");
            }

            // Get the value of the first argument as a string.
            var arg0 = args[0].ToString();

            // Special method that saves the content of the XML.
            if (binder.Name == "Save" && !this.IsLiteratState)
            {
                var asStream = args[0] as Stream;
                if (asStream.IsNotNull())
                {
                    this.Save(asStream);
                    return true;
                }
                this.Save(arg0);
                return true;
            }

            // start a "save point" this can be used to go back to the midle of the document later.
            if (binder.Name == "sp" && !this.IsLiteratState)
            {
                this.setPoints[arg0] = new DynaXmlBuilderContext(this.context);
                return true;
            }

            // reload previously created save point.
            if (binder.Name == "rp" && !this.IsLiteratState)
            {
                this.context = this.setPoints[arg0];
                return true;
            }

            // Creates a Text block with the content supplied.
            if (binder.Name == "text" && !this.IsLiteratState)
            {
                return this.TextInvokeMember(arg0);
            }

            // Creates a CDATA block with the content supplied.
            if (binder.Name == "cdata" && !this.IsLiteratState)
            {
                return this.CDataInvokeMember(arg0);
            }

            // Sets the default namespace for the current element.
            if (binder.Name == "xmlns" &&
                !this.IsLiteratState)
            {
                this.SetDefaultNamespace(arg0);
                return true;
            }

            switch (this.State)
            {
                case DynaXmlBuilderState.NamespaceBuilder:
                    return this.NamespaceBuilderInvokeMember(binder.Name, arg0);
                case DynaXmlBuilderState.AttributeBuilder:
                case DynaXmlBuilderState.AttributeListBuilder:
                case DynaXmlBuilderState.LiteralAttributeBuilder:
                    return this.AttributeBuilderInvokeMember(binder.Name, arg0);
                case DynaXmlBuilderState.ElementListBuilder:
                case DynaXmlBuilderState.LiteralElementBuilder:
                    return this.ElementBuilderInvokeMember(binder.Name, arg0);
                //case DynaXmlBuilderState.NamespaceBuilder:
                //    return this.NamespaceBuilderInvokeMember(binder, args);
            }
            return base.TryInvokeMember(binder, args, out result);
        }
コード例 #6
0
        /// <inheritdoc />
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            // For interface flowing, the resulting object is always this object.
            result = this;
            if (binder == null)
            {
                throw new ArgumentNullException("binder");
            }

            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            // Ends the line of chaining.
            if (binder.Name == "End" && !this.IsLiteratState)
            {
                return(true);
            }

            if (args.Length == 0 || args[0].IsNull())
            {
                if (this.IsElementState)
                {
                    this.ElementBuilderInvokeMember(binder.Name, string.Empty);
                }
                throw new ArgumentOutOfRangeException("args");
            }

            // Get the value of the first argument as a string.
            var arg0 = args[0].ToString();

            // Special method that saves the content of the XML.
            if (binder.Name == "Save" && !this.IsLiteratState)
            {
                var asStream = args[0] as Stream;
                if (asStream.IsNotNull())
                {
                    this.Save(asStream);
                    return(true);
                }
                this.Save(arg0);
                return(true);
            }

            // start a "save point" this can be used to go back to the midle of the document later.
            if (binder.Name == "sp" && !this.IsLiteratState)
            {
                this.setPoints[arg0] = new DynaXmlBuilderContext(this.context);
                return(true);
            }

            // reload previously created save point.
            if (binder.Name == "rp" && !this.IsLiteratState)
            {
                this.context = this.setPoints[arg0];
                return(true);
            }

            // Creates a Text block with the content supplied.
            if (binder.Name == "text" && !this.IsLiteratState)
            {
                return(this.TextInvokeMember(arg0));
            }

            // Creates a CDATA block with the content supplied.
            if (binder.Name == "cdata" && !this.IsLiteratState)
            {
                return(this.CDataInvokeMember(arg0));
            }

            // Sets the default namespace for the current element.
            if (binder.Name == "xmlns" &&
                !this.IsLiteratState)
            {
                this.SetDefaultNamespace(arg0);
                return(true);
            }

            switch (this.State)
            {
            case DynaXmlBuilderState.NamespaceBuilder:
                return(this.NamespaceBuilderInvokeMember(binder.Name, arg0));

            case DynaXmlBuilderState.AttributeBuilder:
            case DynaXmlBuilderState.AttributeListBuilder:
            case DynaXmlBuilderState.LiteralAttributeBuilder:
                return(this.AttributeBuilderInvokeMember(binder.Name, arg0));

            case DynaXmlBuilderState.ElementListBuilder:
            case DynaXmlBuilderState.LiteralElementBuilder:
                return(this.ElementBuilderInvokeMember(binder.Name, arg0));
                //case DynaXmlBuilderState.NamespaceBuilder:
                //    return this.NamespaceBuilderInvokeMember(binder, args);
            }
            return(base.TryInvokeMember(binder, args, out result));
        }