//\r
// System.IO.StringWriter\r
//\r
-// Authors
-// Marcin Szczepanski (marcins@zipworld.com.au)
-// Sebastien Pouliot <sebastien@ximian.com>
-//
-// Copyright (C) 2004 Novell (http://www.novell.com)\r
+// Authors\r
+// Marcin Szczepanski (marcins@zipworld.com.au)\r
+// Sebastien Pouliot <sebastien@ximian.com>\r
+// Marek Safar (marek.safar@gmail.com)\r
//\r
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
+//\r
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)\r
+// Copyright 2011 Xamarin Inc.\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the\r
+// "Software"), to deal in the Software without restriction, including\r
+// without limitation the rights to use, copy, modify, merge, publish,\r
+// distribute, sublicense, and/or sell copies of the Software, and to\r
+// permit persons to whom the Software is furnished to do so, subject to\r
+// the following conditions:\r
+// \r
+// The above copyright notice and this permission notice shall be\r
+// included in all copies or substantial portions of the Software.\r
+// \r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+\r
using System.Globalization;\r
using System.Text;\r
+using System.Runtime.InteropServices;\r
+#if NET_4_5\r
+using System.Threading.Tasks;\r
+#endif\r
\r
-namespace System.IO {\r
-
+namespace System.IO\r
+{\r
[Serializable]\r
- [MonoTODO ("Fix serialization compatibility with MS.NET")]\r
- public class StringWriter : TextWriter {\r
- \r
- private StringBuilder internalString;\r
- private bool disposed = false;\r
+ [ComVisible (true)]\r
+ [MonoLimitation ("Serialization format not compatible with .NET")]\r
+ public class StringWriter : TextWriter\r
+ {\r
+ private StringBuilder internalString;\r
+ private bool disposed;\r
\r
- public StringWriter () : this (new StringBuilder ())
- {
+ public StringWriter ()\r
+ : this (new StringBuilder ())\r
+ {\r
}\r
\r
- public StringWriter (IFormatProvider formatProvider) :
- this (new StringBuilder (), formatProvider)
- {
+ public StringWriter (IFormatProvider formatProvider)\r
+ : this (new StringBuilder (), formatProvider)\r
+ {\r
}\r
\r
- public StringWriter (StringBuilder sb) :
- this (sb, null)
+ public StringWriter (StringBuilder sb)\r
+ : this (sb, null)\r
{\r
}\r
\r
- public StringWriter (StringBuilder sb, IFormatProvider formatProvider)
+ public StringWriter (StringBuilder sb, IFormatProvider formatProvider)\r
{\r
if (sb == null)\r
throw new ArgumentNullException ("sb");\r
internalFormatProvider = formatProvider;\r
}\r
\r
- public override System.Text.Encoding Encoding {\r
- get {\r
- return System.Text.Encoding.Unicode;\r
- }\r
+ public override Encoding Encoding {\r
+ get {\r
+ return Encoding.Unicode;\r
+ }\r
}\r
\r
- public override void Close ()
+ public override void Close ()\r
{\r
Dispose (true);\r
disposed = true;\r
- }\r
+ }\r
\r
- protected override void Dispose (bool disposing)\r
+ protected override void Dispose (bool disposing)\r
{\r
// MS.NET doesn't clear internal buffer.\r
// internalString = null;\r
disposed = true;\r
}\r
\r
- public virtual StringBuilder GetStringBuilder ()
+ public virtual StringBuilder GetStringBuilder ()\r
{\r
return internalString;\r
}\r
\r
- public override string ToString ()
+ public override string ToString ()\r
{\r
return internalString.ToString ();\r
- }\r
+ }\r
\r
- public override void Write (char value)
+ public override void Write (char value)\r
{\r
if (disposed) {\r
- throw new ObjectDisposedException ("StringReader",
- Locale.GetText ("Cannot write to a closed StringWriter"));
+ throw new ObjectDisposedException ("StringReader",\r
+ Locale.GetText ("Cannot write to a closed StringWriter"));\r
}\r
\r
- internalString.Append (value);\r
+ internalString.Append (value);\r
}\r
\r
- public override void Write (string value)
+ public override void Write (string value)\r
{\r
if (disposed) {\r
- throw new ObjectDisposedException ("StringReader",
- Locale.GetText ("Cannot write to a closed StringWriter"));
+ throw new ObjectDisposedException ("StringReader",\r
+ Locale.GetText ("Cannot write to a closed StringWriter"));\r
}\r
-
+\r
internalString.Append (value);\r
}\r
\r
- public override void Write (char[] buffer, int index, int count)
+ public override void Write (char[] buffer, int index, int count)\r
{\r
if (disposed) {\r
- throw new ObjectDisposedException ("StringReader",
- Locale.GetText ("Cannot write to a closed StringWriter"));
+ throw new ObjectDisposedException ("StringReader",\r
+ Locale.GetText ("Cannot write to a closed StringWriter"));\r
}\r
if (buffer == null)\r
- throw new ArgumentNullException ("buffer");
+ throw new ArgumentNullException ("buffer");\r
if (index < 0)\r
- throw new ArgumentOutOfRangeException ("index", "< 0");
+ throw new ArgumentOutOfRangeException ("index", "< 0");\r
if (count < 0)\r
- throw new ArgumentOutOfRangeException ("count", "< 0");
- // re-ordered to avoid possible integer overflow
- if (index > buffer.Length - count)\r
+ throw new ArgumentOutOfRangeException ("count", "< 0");\r
+ // re-ordered to avoid possible integer overflow\r
+ if (index > buffer.Length - count)\r
throw new ArgumentException ("index + count > buffer.Length");\r
-
+\r
internalString.Append (buffer, index, count);\r
}\r
+\r
+#if NET_4_5\r
+ public override Task FlushAsync ()\r
+ {\r
+ // it appears to do nothing\r
+ return TaskConstants.Finished;\r
+ }\r
+\r
+ //\r
+ // All async methods return finished task with a result as it's faster\r
+ // than setting up async call\r
+ //\r
+ public override Task WriteAsync (char value)\r
+ {\r
+ Write (value);\r
+ return TaskConstants.Finished;\r
+ }\r
+\r
+ public override Task WriteAsync (char[] buffer, int index, int count)\r
+ {\r
+ Write (buffer, index, count);\r
+ return TaskConstants.Finished;\r
+ }\r
+\r
+ public override Task WriteAsync (string value)\r
+ {\r
+ Write (value);\r
+ return TaskConstants.Finished;\r
+ }\r
+\r
+ public override Task WriteLineAsync (char value)\r
+ {\r
+ WriteLine (value);\r
+ return TaskConstants.Finished;\r
+ }\r
+\r
+ public override Task WriteLineAsync (char[] buffer, int index, int count)\r
+ {\r
+ WriteLine (buffer, index, count);\r
+ return TaskConstants.Finished;\r
+ }\r
+\r
+ public override Task WriteLineAsync (string value)\r
+ {\r
+ WriteLine (value);\r
+ return TaskConstants.Finished;\r
+ }\r
+#endif\r
}\r
-}\r
- \r
+}
\ No newline at end of file