diff options
author | csharptest <roger@csharptest.net> | 2011-06-10 23:54:53 -0500 |
---|---|---|
committer | rogerk <devnull@localhost> | 2011-06-10 23:54:53 -0500 |
commit | 7fc785c1d463c4424cf3e3c8d7fbe796e0197b70 (patch) | |
tree | 1ea510abf9dbf61d709e26ba1845b944bb87b8ef /src/ProtocolBuffers/Serialization/XmlFormatWriter.cs | |
parent | ea5fd37d1dbf8229e358d47095f93d362e73cc5d (diff) | |
download | protobuf-7fc785c1d463c4424cf3e3c8d7fbe796e0197b70.tar.gz protobuf-7fc785c1d463c4424cf3e3c8d7fbe796e0197b70.tar.bz2 protobuf-7fc785c1d463c4424cf3e3c8d7fbe796e0197b70.zip |
Reader/Writer implementations changed to use static factories
Diffstat (limited to 'src/ProtocolBuffers/Serialization/XmlFormatWriter.cs')
-rw-r--r-- | src/ProtocolBuffers/Serialization/XmlFormatWriter.cs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/ProtocolBuffers/Serialization/XmlFormatWriter.cs b/src/ProtocolBuffers/Serialization/XmlFormatWriter.cs index b5dbf5fa..2bb4f159 100644 --- a/src/ProtocolBuffers/Serialization/XmlFormatWriter.cs +++ b/src/ProtocolBuffers/Serialization/XmlFormatWriter.cs @@ -1,5 +1,6 @@ using System;
using System.IO;
+using System.Text;
using System.Xml;
using Google.ProtocolBuffers.Descriptors;
@@ -17,23 +18,29 @@ namespace Google.ProtocolBuffers.Serialization private readonly XmlWriter _output;
private string _rootElementName;
- static XmlWriterSettings DefaultSettings
+ static XmlWriterSettings DefaultSettings(Encoding encoding)
{
- get { return new XmlWriterSettings() {CheckCharacters = false, NewLineHandling = NewLineHandling.Entitize}; }
+ return new XmlWriterSettings() { CheckCharacters = false, NewLineHandling = NewLineHandling.Entitize, Encoding = encoding };
}
/// <summary>
/// Constructs the XmlFormatWriter to write to the given TextWriter
/// </summary>
- public XmlFormatWriter(TextWriter output) : this(XmlWriter.Create(output, DefaultSettings)) { }
+ public static XmlFormatWriter CreateInstance(TextWriter output) { return new XmlFormatWriter(XmlWriter.Create(output, DefaultSettings(output.Encoding))); }
/// <summary>
/// Constructs the XmlFormatWriter to write to the given stream
/// </summary>
- public XmlFormatWriter(Stream output) : this(XmlWriter.Create(output, DefaultSettings)) { }
+ public static XmlFormatWriter CreateInstance(Stream output) { return new XmlFormatWriter(XmlWriter.Create(output, DefaultSettings(Encoding.UTF8))); }
+ /// <summary>
+ /// Constructs the XmlFormatWriter to write to the given stream
+ /// </summary>
+ public static XmlFormatWriter CreateInstance(Stream output, Encoding encoding) { return new XmlFormatWriter(XmlWriter.Create(output, DefaultSettings(encoding))); }
/// <summary>
/// Constructs the XmlFormatWriter to write to the given XmlWriter
/// </summary>
- public XmlFormatWriter(XmlWriter output)
+ public static XmlFormatWriter CreateInstance(XmlWriter output) { return new XmlFormatWriter(output); }
+
+ protected XmlFormatWriter(XmlWriter output)
{
_output = output;
_rootElementName = DefaultRootElementName;
@@ -61,6 +68,10 @@ namespace Google.ProtocolBuffers.Serialization /// Gets or sets the options to use while generating the XML
/// </summary>
public XmlWriterOptions Options { get; set; }
+ /// <summary>
+ /// Sets the options to use while generating the XML
+ /// </summary>
+ public XmlFormatWriter SetOptions(XmlWriterOptions options) { Options = options; return this; }
private bool TestOption(XmlWriterOptions option) { return (Options & option) != 0; }
|