@@ -55,7 +55,8 @@ public abstract class ObjectSerializerBase : IObjectSerializer, IStringSerialize
5555 /// <param name="reader">The reader.</param>
5656 /// <param name="type">The type.</param>
5757 /// <returns>System.Object.</returns>
58- public object Deserialize ( TextReader reader , Type type ) {
58+ public object Deserialize ( TextReader reader , Type type )
59+ {
5960 return DeserializeCore ( reader , type ) ;
6061 }
6162
@@ -65,7 +66,8 @@ public object Deserialize(TextReader reader, Type type) {
6566 /// <param name="stream">The stream.</param>
6667 /// <param name="type">The type.</param>
6768 /// <returns>System.Object.</returns>
68- public virtual object Deserialize ( Stream stream , Type type ) {
69+ public virtual object Deserialize ( Stream stream , Type type )
70+ {
6971#if NET40
7072 using ( StreamReader reader = new StreamReader ( stream , Encoding , true , bufferSize ) )
7173#else
@@ -80,8 +82,10 @@ public virtual object Deserialize(Stream stream, Type type) {
8082 /// <param name="data">The data.</param>
8183 /// <param name="type">The type.</param>
8284 /// <returns>System.Object.</returns>
83- public virtual object Deserialize ( byte [ ] data , Type type ) {
84- using ( var mem = MemoryStreamFactory . GetStream ( data ) ) {
85+ public virtual object Deserialize ( byte [ ] data , Type type )
86+ {
87+ using ( var mem = MemoryStreamFactory . GetStream ( data ) )
88+ {
8589 return Deserialize ( mem , type ) ;
8690 }
8791 }
@@ -91,7 +95,8 @@ public virtual object Deserialize(byte[] data, Type type) {
9195 /// </summary>
9296 /// <param name="value">The value.</param>
9397 /// <param name="writer">The writer.</param>
94- public void Serialize ( object value , TextWriter writer ) {
98+ public void Serialize ( object value , TextWriter writer )
99+ {
95100 SerializeCore ( value , writer ) ;
96101 }
97102
@@ -100,7 +105,8 @@ public void Serialize(object value, TextWriter writer) {
100105 /// </summary>
101106 /// <param name="value">The value.</param>
102107 /// <param name="output">The output.</param>
103- public virtual void Serialize ( object value , Stream output ) {
108+ public virtual void Serialize ( object value , Stream output )
109+ {
104110#if NET40
105111 using ( StreamWriter sw = new StreamWriter ( output , Encoding , bufferSize ) )
106112#else
@@ -114,8 +120,10 @@ public virtual void Serialize(object value, Stream output) {
114120 /// </summary>
115121 /// <param name="value">The value.</param>
116122 /// <param name="output">The output.</param>
117- public virtual void Serialize ( object value , out byte [ ] output ) {
118- using ( var mem = MemoryStreamFactory . GetStream ( ) ) {
123+ public virtual void Serialize ( object value , out byte [ ] output )
124+ {
125+ using ( var mem = MemoryStreamFactory . GetStream ( ) )
126+ {
119127 Serialize ( value , mem ) ;
120128 output = mem . ToArray ( ) ;
121129 }
@@ -126,10 +134,20 @@ public virtual void Serialize(object value, out byte[] output) {
126134 /// </summary>
127135 /// <param name="value">The value.</param>
128136 /// <returns>System.String.</returns>
129- public virtual string SerializeToString ( object value ) {
130- using ( StringWriter writer = new StringWriter ( ) ) {
131- SerializeCore ( value , writer ) ;
132- return writer . ToString ( ) ;
137+ public virtual string SerializeToString ( object value )
138+ {
139+ using ( var ms = MemoryStreamFactory . GetStream ( ) )
140+ {
141+ using ( StreamWriter writer = new StreamWriter ( ms ) )
142+ {
143+ SerializeCore ( value , writer ) ;
144+
145+ writer . Flush ( ) ;
146+
147+ ms . Seek ( 0 , SeekOrigin . Begin ) ;
148+ var reader = new StreamReader ( ms ) ;
149+ return reader . ReadToEnd ( ) ;
150+ }
133151 }
134152 }
135153
@@ -139,8 +157,10 @@ public virtual string SerializeToString(object value) {
139157 /// <param name="serializedText">The serialized text.</param>
140158 /// <param name="type">The type.</param>
141159 /// <returns>System.Object.</returns>
142- public virtual object DeserializeFromString ( string serializedText , Type type ) {
143- using ( StringReader reader = new StringReader ( serializedText ) ) {
160+ public virtual object DeserializeFromString ( string serializedText , Type type )
161+ {
162+ using ( StringReader reader = new StringReader ( serializedText ) )
163+ {
144164 return DeserializeCore ( reader , type ) ;
145165 }
146166 }
@@ -151,7 +171,8 @@ public virtual object DeserializeFromString(string serializedText, Type type) {
151171 /// </summary>
152172 /// <param name="data">The data.</param>
153173 /// <returns>System.String.</returns>
154- protected static string ToHex ( byte [ ] data ) {
174+ protected static string ToHex ( byte [ ] data )
175+ {
155176 return BitConverter . ToString ( data ) . Replace ( "-" , string . Empty ) ;
156177 }
157178
@@ -161,7 +182,8 @@ protected static string ToHex(byte[] data) {
161182 /// </summary>
162183 /// <param name="hex">The hexadecimal.</param>
163184 /// <returns>System.Byte[].</returns>
164- protected static byte [ ] FromHex ( string hex ) {
185+ protected static byte [ ] FromHex ( string hex )
186+ {
165187 if ( string . IsNullOrEmpty ( hex ) ) return new byte [ 0 ] ;
166188 if ( ( hex . Length % 2 ) != 0 )
167189 hex += " " ;
0 commit comments