From 353b0fad9042c183de3f874cde072f75a60d8d2a Mon Sep 17 00:00:00 2001 From: csharptest Date: Thu, 29 Sep 2011 16:33:31 -0500 Subject: [PATCH] Changes from code review --- .../AbstractWriter.cs | 19 +------------------ .../Http/MessageFormatOptions.cs | 2 +- .../JsonFormatWriter.cs | 18 +----------------- .../XmlFormatReader.cs | 16 ++++++++-------- .../XmlFormatWriter.cs | 18 ------------------ .../TestWriterFormatJson.cs | 2 +- .../TestWriterFormatXml.cs | 2 +- src/ProtocolBuffers/CodedOutputStream.cs | 14 +------------- src/ProtocolBuffers/ICodedOutputStream.cs | 2 +- 9 files changed, 15 insertions(+), 78 deletions(-) diff --git a/src/ProtocolBuffers.Serialization/AbstractWriter.cs b/src/ProtocolBuffers.Serialization/AbstractWriter.cs index 7ae268646f..1e087ec676 100644 --- a/src/ProtocolBuffers.Serialization/AbstractWriter.cs +++ b/src/ProtocolBuffers.Serialization/AbstractWriter.cs @@ -12,18 +12,8 @@ namespace Google.ProtocolBuffers.Serialization /// /// Provides a base class for writers that performs some basic type dispatching /// - public abstract class AbstractWriter : ICodedOutputStream, IDisposable + public abstract class AbstractWriter : ICodedOutputStream { - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - GC.SuppressFinalize(this); - Flush(); - Dispose(true); - } - /// /// Completes any pending write operations /// @@ -31,13 +21,6 @@ namespace Google.ProtocolBuffers.Serialization { } - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - protected virtual void Dispose(bool disposing) - { - } - /// /// Writes the message to the the formatted stream. /// diff --git a/src/ProtocolBuffers.Serialization/Http/MessageFormatOptions.cs b/src/ProtocolBuffers.Serialization/Http/MessageFormatOptions.cs index 4ee18891ef..72d737171d 100644 --- a/src/ProtocolBuffers.Serialization/Http/MessageFormatOptions.cs +++ b/src/ProtocolBuffers.Serialization/Http/MessageFormatOptions.cs @@ -8,7 +8,7 @@ namespace Google.ProtocolBuffers.Serialization.Http /// /// Defines control information for the various formatting used with HTTP services /// - public struct MessageFormatOptions + public class MessageFormatOptions { /// The mime type for xml content /// Other valid xml mime types include: application/binary, application/x-protobuf diff --git a/src/ProtocolBuffers.Serialization/JsonFormatWriter.cs b/src/ProtocolBuffers.Serialization/JsonFormatWriter.cs index 15e08e0522..035870df23 100644 --- a/src/ProtocolBuffers.Serialization/JsonFormatWriter.cs +++ b/src/ProtocolBuffers.Serialization/JsonFormatWriter.cs @@ -239,27 +239,11 @@ namespace Google.ProtocolBuffers.Serialization /// Gets or sets the whitespace to use to separate the text, default = empty public string Whitespace { get; set; } - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - protected override void Dispose(bool disposing) - { - if (disposing) - { - while (_counter.Count > 1) - { - WriteMessageEnd(); - } - } - - base.Dispose(disposing); - } - private void Seperator() { if (_counter.Count == 0) { - throw new InvalidOperationException("Missmatched open/close in Json writer."); + throw new InvalidOperationException("Mismatched open/close in Json writer."); } int index = _counter.Count - 1; diff --git a/src/ProtocolBuffers.Serialization/XmlFormatReader.cs b/src/ProtocolBuffers.Serialization/XmlFormatReader.cs index 98b6977678..bf21db5545 100644 --- a/src/ProtocolBuffers.Serialization/XmlFormatReader.cs +++ b/src/ProtocolBuffers.Serialization/XmlFormatReader.cs @@ -14,16 +14,16 @@ namespace Google.ProtocolBuffers.Serialization { public const string DefaultRootElementName = XmlFormatWriter.DefaultRootElementName; private readonly XmlReader _input; - private readonly Stack _elements; + private readonly Stack _elements; private string _rootElementName; - private struct ElementStack + private struct ElementStackEntry { public readonly string LocalName; public readonly int Depth; public readonly bool IsEmpty; - public ElementStack(string localName, int depth, bool isEmpty) : this() + public ElementStackEntry(string localName, int depth, bool isEmpty) : this() { LocalName = localName; IsEmpty = isEmpty; @@ -87,7 +87,7 @@ namespace Google.ProtocolBuffers.Serialization { _input = input; _rootElementName = DefaultRootElementName; - _elements = new Stack(); + _elements = new Stack(); Options = XmlReaderOptions.None; } @@ -144,7 +144,7 @@ namespace Google.ProtocolBuffers.Serialization continue; } Assert(_input.IsStartElement() && _input.LocalName == element); - _elements.Push(new ElementStack(element, _input.Depth, _input.IsEmptyElement)); + _elements.Push(new ElementStackEntry(element, _input.Depth, _input.IsEmptyElement)); _input.Read(); } @@ -156,7 +156,7 @@ namespace Google.ProtocolBuffers.Serialization { Assert(_elements.Count > 0); - ElementStack stop = _elements.Peek(); + ElementStackEntry stop = _elements.Peek(); while (_input.NodeType != XmlNodeType.EndElement && _input.NodeType != XmlNodeType.Element && _input.Depth > stop.Depth && _input.Read()) { @@ -211,10 +211,10 @@ namespace Google.ProtocolBuffers.Serialization /// protected override bool PeekNext(out string field) { - ElementStack stopNode; + ElementStackEntry stopNode; if (_elements.Count == 0) { - stopNode = new ElementStack(null, _input.Depth - 1, false); + stopNode = new ElementStackEntry(null, _input.Depth - 1, false); } else { diff --git a/src/ProtocolBuffers.Serialization/XmlFormatWriter.cs b/src/ProtocolBuffers.Serialization/XmlFormatWriter.cs index 3c5cb3ab16..fc3f9dc2ca 100644 --- a/src/ProtocolBuffers.Serialization/XmlFormatWriter.cs +++ b/src/ProtocolBuffers.Serialization/XmlFormatWriter.cs @@ -71,24 +71,6 @@ namespace Google.ProtocolBuffers.Serialization _rootElementName = DefaultRootElementName; } - /// - /// Closes the underlying XmlTextWriter - /// - protected override void Dispose(bool disposing) - { - if (disposing) - { - while (_messageOpenCount > 0) - { - WriteMessageEnd(); - } - - _output.Close(); - } - - base.Dispose(disposing); - } - /// /// Gets or sets the default element name to use when using the Merge<TBuilder>() /// diff --git a/src/ProtocolBuffers.Test/TestWriterFormatJson.cs b/src/ProtocolBuffers.Test/TestWriterFormatJson.cs index 1958df0de3..1a1a480d9d 100644 --- a/src/ProtocolBuffers.Test/TestWriterFormatJson.cs +++ b/src/ProtocolBuffers.Test/TestWriterFormatJson.cs @@ -43,8 +43,8 @@ namespace Google.ProtocolBuffers .Build(); using (TextWriter output = new StringWriter()) - using (AbstractWriter writer = JsonFormatWriter.CreateInstance(output)) { + ICodedOutputStream writer = JsonFormatWriter.CreateInstance(output); writer.WriteMessageStart(); //manually begin the message, output is '{' writer.Flush(); diff --git a/src/ProtocolBuffers.Test/TestWriterFormatXml.cs b/src/ProtocolBuffers.Test/TestWriterFormatXml.cs index f401481eec..46853582b1 100644 --- a/src/ProtocolBuffers.Test/TestWriterFormatXml.cs +++ b/src/ProtocolBuffers.Test/TestWriterFormatXml.cs @@ -46,8 +46,8 @@ namespace Google.ProtocolBuffers .Build(); using (TextWriter output = new StringWriter()) - using (AbstractWriter writer = XmlFormatWriter.CreateInstance(output)) { + ICodedOutputStream writer = XmlFormatWriter.CreateInstance(output); writer.WriteMessageStart(); //manually begin the message, output is '{' ICodedOutputStream stream = writer; diff --git a/src/ProtocolBuffers/CodedOutputStream.cs b/src/ProtocolBuffers/CodedOutputStream.cs index 709082a71d..b9c7b58740 100644 --- a/src/ProtocolBuffers/CodedOutputStream.cs +++ b/src/ProtocolBuffers/CodedOutputStream.cs @@ -57,7 +57,7 @@ namespace Google.ProtocolBuffers /// methods are taken from the protocol buffer type names, not .NET types. /// (Hence WriteFloat instead of WriteSingle, and WriteBool instead of WriteBoolean.) /// - public sealed partial class CodedOutputStream : ICodedOutputStream, IDisposable + public sealed partial class CodedOutputStream : ICodedOutputStream { /// /// The buffer size used by CreateInstance(Stream). @@ -126,18 +126,6 @@ namespace Google.ProtocolBuffers #endregion - public void Dispose() - { - if (output != null) - { - if (position > 0) - { - Flush(); - } - output.Dispose(); - } - } - void ICodedOutputStream.WriteMessageStart() { } void ICodedOutputStream.WriteMessageEnd() { Flush(); } diff --git a/src/ProtocolBuffers/ICodedOutputStream.cs b/src/ProtocolBuffers/ICodedOutputStream.cs index a686fed178..8619508a1c 100644 --- a/src/ProtocolBuffers/ICodedOutputStream.cs +++ b/src/ProtocolBuffers/ICodedOutputStream.cs @@ -49,7 +49,7 @@ namespace Google.ProtocolBuffers /// in their binary form by creating a instance via the CodedOutputStream.CreateInstance /// static factory. /// - public interface ICodedOutputStream : IDisposable + public interface ICodedOutputStream { /// /// Writes any message initialization data needed to the output stream