@@ -15,7 +15,8 @@ namespace ServiceStack.Text
15
15
{
16
16
public class CsvSerializer
17
17
{
18
- public static UTF8Encoding UTF8Encoding = new UTF8Encoding ( false ) ; //Don't emit UTF8 BOM by default
18
+ //Don't emit UTF8 BOM by default
19
+ public static Encoding UseEncoding { get ; set ; } = new UTF8Encoding ( false ) ;
19
20
20
21
private static Dictionary < Type , WriteObjectDelegate > WriteFnCache = new Dictionary < Type , WriteObjectDelegate > ( ) ;
21
22
internal static WriteObjectDelegate GetWriteFn ( Type type )
@@ -116,15 +117,15 @@ public static void SerializeToWriter<T>(T value, TextWriter writer)
116
117
public static void SerializeToStream < T > ( T value , Stream stream )
117
118
{
118
119
if ( value == null ) return ;
119
- var writer = new StreamWriter ( stream , UTF8Encoding ) ;
120
+ var writer = new StreamWriter ( stream , UseEncoding ) ;
120
121
CsvSerializer < T > . WriteObject ( writer , value ) ;
121
122
writer . Flush ( ) ;
122
123
}
123
124
124
125
public static void SerializeToStream ( object obj , Stream stream )
125
126
{
126
127
if ( obj == null ) return ;
127
- var writer = new StreamWriter ( stream , UTF8Encoding ) ;
128
+ var writer = new StreamWriter ( stream , UseEncoding ) ;
128
129
var writeFn = GetWriteFn ( obj . GetType ( ) ) ;
129
130
writeFn ( writer , obj ) ;
130
131
writer . Flush ( ) ;
@@ -133,7 +134,7 @@ public static void SerializeToStream(object obj, Stream stream)
133
134
public static T DeserializeFromStream < T > ( Stream stream )
134
135
{
135
136
if ( stream == null ) return default ( T ) ;
136
- using ( var reader = new StreamReader ( stream , UTF8Encoding ) )
137
+ using ( var reader = new StreamReader ( stream , UseEncoding ) )
137
138
{
138
139
return DeserializeFromString < T > ( reader . ReadToEnd ( ) ) ;
139
140
}
@@ -142,7 +143,7 @@ public static T DeserializeFromStream<T>(Stream stream)
142
143
public static object DeserializeFromStream ( Type type , Stream stream )
143
144
{
144
145
if ( stream == null ) return null ;
145
- using ( var reader = new StreamReader ( stream , UTF8Encoding ) )
146
+ using ( var reader = new StreamReader ( stream , UseEncoding ) )
146
147
{
147
148
return DeserializeFromString ( type , reader . ReadToEnd ( ) ) ;
148
149
}
0 commit comments