Exemplo n.º 1
0
        public static XmlWriter Create(XmlWriter output, XmlWriterSettings settings)
        {
            if (settings == null)
            {
                settings = new XmlWriterSettings();
            }
            else
            {
                settings = settings.Clone();
            }

            var src = output.Settings;

            if (src == null)
            {
                settings.ConformanceLevel = ConformanceLevel.Document;                 // Huh? Why??
                output = new DefaultXmlWriter(output);
#if NET_4_5
                settings.SetReadOnly();
#endif
                output.settings = settings;
            }
            else
            {
                ConformanceLevel dst = src.ConformanceLevel;
                switch (src.ConformanceLevel)
                {
                case ConformanceLevel.Auto:
                    dst = settings.ConformanceLevel;
                    break;

                case ConformanceLevel.Document:
                case ConformanceLevel.Fragment:
                    if (settings.ConformanceLevel != ConformanceLevel.Auto)
                    {
                        dst = settings.ConformanceLevel;
                    }
                    break;
                }

                settings.MergeFrom(src);

#if NET_4_5
                settings.SetReadOnly();
#endif

                // It returns a new XmlWriter instance if 1) Settings is null, or 2) Settings ConformanceLevel (or might be other members as well) give significant difference.
                if (src.ConformanceLevel != dst)
                {
                    output          = new DefaultXmlWriter(output, false);
                    output.settings = settings;
                }
            }

            return(output);
        }
Exemplo n.º 2
0
        public static XmlWriter Create(XmlWriter writer, XmlWriterSettings settings)
        {
            if (settings == null)
            {
                settings = new XmlWriterSettings();
            }
            else
            {
                settings = settings.Clone();
            }

            var src = writer.Settings;

            if (src == null)
            {
                settings.ConformanceLevel = ConformanceLevel.Document;                 // Huh? Why??
                writer          = new DefaultXmlWriter(writer);
                writer.settings = settings;
            }
            else
            {
                ConformanceLevel dst = src.ConformanceLevel;
                switch (src.ConformanceLevel)
                {
                case ConformanceLevel.Auto:
                    dst = settings.ConformanceLevel;
                    break;

                case ConformanceLevel.Document:
                case ConformanceLevel.Fragment:
                    if (settings.ConformanceLevel != ConformanceLevel.Auto)
                    {
                        dst = settings.ConformanceLevel;
                    }
                    break;
                }

                settings.MergeFrom(src);

                // It returns a new XmlWriter instance if 1) Settings is null, or 2) Settings ConformanceLevel (or might be other members as well) give significant difference.
                if (src.ConformanceLevel != dst)
                {
                    writer          = new DefaultXmlWriter(writer, false);
                    writer.settings = settings;
                }
            }

            return(writer);
        }
Exemplo n.º 3
0
		public static XmlWriter Create (XmlWriter writer, XmlWriterSettings settings)
		{
			if (settings == null)
				settings = new XmlWriterSettings ();
			else
				settings = settings.Clone ();

			var src = writer.Settings;
			if (src == null) {
				settings.ConformanceLevel = ConformanceLevel.Document; // Huh? Why??
				writer = new DefaultXmlWriter (writer);
				writer.settings = settings;
			} else {
				ConformanceLevel dst = src.ConformanceLevel;
				switch (src.ConformanceLevel) {
				case ConformanceLevel.Auto:
					dst = settings.ConformanceLevel;
					break;
				case ConformanceLevel.Document:
				case ConformanceLevel.Fragment:
					if (settings.ConformanceLevel != ConformanceLevel.Auto)
						dst = settings.ConformanceLevel;
					break;
				}

				settings.MergeFrom (src);

				// It returns a new XmlWriter instance if 1) Settings is null, or 2) Settings ConformanceLevel (or might be other members as well) give significant difference.
				if (src.ConformanceLevel != dst) {
					writer = new DefaultXmlWriter (writer, false);
					writer.settings = settings;
				}
			}

			return writer;
		}
Exemplo n.º 4
0
		public static XmlWriter Create (XmlWriter output, XmlWriterSettings settings)
		{
			if (settings == null)
				settings = new XmlWriterSettings ();
			else
				settings = settings.Clone ();

			var src = output.Settings;
			if (src == null) {
				settings.ConformanceLevel = ConformanceLevel.Document; // Huh? Why??
				output = new DefaultXmlWriter (output);
#if NET_4_5
				settings.SetReadOnly ();
#endif
				output.settings = settings;
			} else {
				ConformanceLevel dst = src.ConformanceLevel;
				switch (src.ConformanceLevel) {
				case ConformanceLevel.Auto:
					dst = settings.ConformanceLevel;
					break;
				case ConformanceLevel.Document:
				case ConformanceLevel.Fragment:
					if (settings.ConformanceLevel != ConformanceLevel.Auto)
						dst = settings.ConformanceLevel;
					break;
				}

				settings.MergeFrom (src);

#if NET_4_5
				settings.SetReadOnly ();
#endif

				// It returns a new XmlWriter instance if 1) Settings is null, or 2) Settings ConformanceLevel (or might be other members as well) give significant difference.
				if (src.ConformanceLevel != dst) {
					output = new DefaultXmlWriter (output, false);
					output.settings = settings;
				}
			}

			return output;
		}