2 // XmlWriterSettings.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // (C) 2004 Novell Inc.
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System.Xml.Schema;
40 public sealed class XmlWriterSettings
42 private bool checkCharacters;
43 private bool closeOutput;
44 private ConformanceLevel conformance;
45 private Encoding encoding;
47 private string indentChars;
48 private string newLineChars;
49 private bool newLineOnAttributes;
50 private NewLineHandling newLineHandling;
51 private bool omitXmlDeclaration;
52 private XmlOutputMethod outputMethod;
55 private bool isReadOnly;
59 public XmlWriterSettings ()
64 public XmlWriterSettings Clone ()
66 return (XmlWriterSettings) MemberwiseClone ();
69 // This might better be rewrite to "examine two settings and return the existing one or new one if required".
70 internal void MergeFrom (XmlWriterSettings other)
72 CloseOutput |= other.CloseOutput;
73 OmitXmlDeclaration |= other.OmitXmlDeclaration;
74 if (ConformanceLevel == ConformanceLevel.Auto)
75 ConformanceLevel = other.ConformanceLevel;
80 checkCharacters = true;
81 closeOutput = false; // ? not documented
82 conformance = ConformanceLevel.Document;
83 encoding = Encoding.UTF8;
86 newLineChars = "\r\n";
87 newLineOnAttributes = false;
88 newLineHandling = NewLineHandling.Replace;
89 omitXmlDeclaration = false;
90 outputMethod = XmlOutputMethod.AutoDetect;
96 // It affects only on XmlTextWriter
97 public bool CheckCharacters {
98 get { return checkCharacters; }
99 set { checkCharacters = value; }
102 // It affects only on XmlTextWriter
103 public bool CloseOutput {
104 get { return closeOutput; }
105 set { closeOutput = value; }
108 // It affects only on XmlTextWriter????
109 public ConformanceLevel ConformanceLevel {
110 get { return conformance; }
111 set { conformance = value; }
114 public Encoding Encoding {
115 get { return encoding; }
116 set { encoding = value; }
119 // It affects only on XmlTextWriter
121 get { return indent; }
122 set { indent = value; }
125 // It affects only on XmlTextWriter
126 public string IndentChars {
127 get { return indentChars; }
128 set { indentChars = value; }
131 // It affects only on XmlTextWriter
132 public string NewLineChars {
133 get { return newLineChars; }
136 throw new ArgumentNullException ("value");
137 newLineChars = value;
141 // It affects only on XmlTextWriter
142 public bool NewLineOnAttributes {
143 get { return newLineOnAttributes; }
144 set { newLineOnAttributes = value; }
147 // It affects only on XmlTextWriter
148 public NewLineHandling NewLineHandling {
149 get { return newLineHandling; }
150 set { newLineHandling = value; }
153 // It affects only on XmlTextWriter
154 public bool OmitXmlDeclaration {
155 get { return omitXmlDeclaration; }
156 set { omitXmlDeclaration = value; }
159 // does it affect only on XmlTextWriter?
160 public XmlOutputMethod OutputMethod {
161 get { return outputMethod; }
162 //set { outputMethod = value; }
170 NamespaceHandling NamespaceHandling { get; set; }
173 internal void SetReadOnly ()
179 * FIXME: The .NET 4.5 runtime throws an exception when attempting to
180 * modify any of the properties after the XmlReader has been constructed.
182 void EnsureWritability ()
185 throw new InvalidOperationException ("XmlReaderSettings in read-only");
189 get { return isAsync; }
191 EnsureWritability ();