Files
2026-06-04 11:42:34 +02:00

177 lines
7.2 KiB
C#

using System;
using System.Runtime.InteropServices;
using System.Text;
namespace System.IO
{
/// <summary>Implements a <see cref="T:System.IO.TextWriter" /> for writing information to a string. The information is stored in an underlying <see cref="T:System.Text.StringBuilder" />.</summary>
/// <filterpriority>2</filterpriority>
// Token: 0x020001D2 RID: 466
[MonoTODO("Serialization format not compatible with .NET")]
[ComVisible(true)]
[Serializable]
public class StringWriter : TextWriter
{
/// <summary>Initializes a new instance of the <see cref="T:System.IO.StringWriter" /> class.</summary>
// Token: 0x060017E4 RID: 6116 RVA: 0x0005C1C0 File Offset: 0x0005A3C0
public StringWriter()
: this(new StringBuilder())
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.IO.StringWriter" /> class with the specified format control.</summary>
/// <param name="formatProvider">An <see cref="T:System.IFormatProvider" /> object that controls formatting. </param>
// Token: 0x060017E5 RID: 6117 RVA: 0x0005C1D0 File Offset: 0x0005A3D0
public StringWriter(IFormatProvider formatProvider)
: this(new StringBuilder(), formatProvider)
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.IO.StringWriter" /> class that writes to the specified <see cref="T:System.Text.StringBuilder" />.</summary>
/// <param name="sb">The StringBuilder to write to. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="sb" /> is null. </exception>
// Token: 0x060017E6 RID: 6118 RVA: 0x0005C1E0 File Offset: 0x0005A3E0
public StringWriter(StringBuilder sb)
: this(sb, null)
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.IO.StringWriter" /> class that writes to the specified <see cref="T:System.Text.StringBuilder" /> and has the specified format provider.</summary>
/// <param name="sb">The StringBuilder to write to. </param>
/// <param name="formatProvider">An <see cref="T:System.IFormatProvider" /> object that controls formatting. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="sb" /> is null. </exception>
// Token: 0x060017E7 RID: 6119 RVA: 0x0005C1EC File Offset: 0x0005A3EC
public StringWriter(StringBuilder sb, IFormatProvider formatProvider)
{
if (sb == null)
{
throw new ArgumentNullException("sb");
}
this.internalString = sb;
this.internalFormatProvider = formatProvider;
}
/// <summary>Gets the <see cref="T:System.Text.Encoding" /> in which the output is written.</summary>
/// <returns>The Encoding in which the output is written.</returns>
/// <filterpriority>1</filterpriority>
// Token: 0x1700043B RID: 1083
// (get) Token: 0x060017E8 RID: 6120 RVA: 0x0005C214 File Offset: 0x0005A414
public override Encoding Encoding
{
get
{
return Encoding.Unicode;
}
}
/// <summary>Closes the current <see cref="T:System.IO.StringWriter" /> and the underlying stream.</summary>
/// <filterpriority>1</filterpriority>
// Token: 0x060017E9 RID: 6121 RVA: 0x0005C21C File Offset: 0x0005A41C
public override void Close()
{
this.Dispose(true);
this.disposed = true;
}
/// <summary>Releases the unmanaged resources used by the <see cref="T:System.IO.StringWriter" /> and optionally releases the managed resources.</summary>
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources. </param>
// Token: 0x060017EA RID: 6122 RVA: 0x0005C22C File Offset: 0x0005A42C
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
this.disposed = true;
}
/// <summary>Returns the underlying <see cref="T:System.Text.StringBuilder" />.</summary>
/// <returns>The underlying StringBuilder.</returns>
/// <filterpriority>2</filterpriority>
// Token: 0x060017EB RID: 6123 RVA: 0x0005C23C File Offset: 0x0005A43C
public virtual StringBuilder GetStringBuilder()
{
return this.internalString;
}
/// <summary>Returns a string containing the characters written to the current StringWriter so far.</summary>
/// <returns>The string containing the characters written to the current StringWriter.</returns>
/// <filterpriority>2</filterpriority>
// Token: 0x060017EC RID: 6124 RVA: 0x0005C244 File Offset: 0x0005A444
public override string ToString()
{
return this.internalString.ToString();
}
/// <summary>Writes a character to this instance of the StringWriter.</summary>
/// <param name="value">The character to write. </param>
/// <exception cref="T:System.ObjectDisposedException">The writer is closed. </exception>
/// <filterpriority>2</filterpriority>
// Token: 0x060017ED RID: 6125 RVA: 0x0005C254 File Offset: 0x0005A454
public override void Write(char value)
{
if (this.disposed)
{
throw new ObjectDisposedException("StringReader", Locale.GetText("Cannot write to a closed StringWriter"));
}
this.internalString.Append(value);
}
/// <summary>Writes a string to this instance of the StringWriter.</summary>
/// <param name="value">The string to write. </param>
/// <exception cref="T:System.ObjectDisposedException">The writer is closed. </exception>
/// <filterpriority>2</filterpriority>
// Token: 0x060017EE RID: 6126 RVA: 0x0005C284 File Offset: 0x0005A484
public override void Write(string value)
{
if (this.disposed)
{
throw new ObjectDisposedException("StringReader", Locale.GetText("Cannot write to a closed StringWriter"));
}
this.internalString.Append(value);
}
/// <summary>Writes the specified region of a character array to this instance of the StringWriter.</summary>
/// <param name="buffer">The character array to read data from. </param>
/// <param name="index">The index at which to begin reading from <paramref name="buffer" />. </param>
/// <param name="count">The maximum number of characters to write. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="buffer" /> is null. </exception>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// <paramref name="index" /> or <paramref name="count" /> is negative. </exception>
/// <exception cref="T:System.ArgumentException">(<paramref name="index" /> + <paramref name="count" />)&gt; <paramref name="buffer" />. Length. </exception>
/// <exception cref="T:System.ObjectDisposedException">The writer is closed. </exception>
/// <filterpriority>2</filterpriority>
// Token: 0x060017EF RID: 6127 RVA: 0x0005C2B4 File Offset: 0x0005A4B4
public override void Write(char[] buffer, int index, int count)
{
if (this.disposed)
{
throw new ObjectDisposedException("StringReader", Locale.GetText("Cannot write to a closed StringWriter"));
}
if (buffer == null)
{
throw new ArgumentNullException("buffer");
}
if (index < 0)
{
throw new ArgumentOutOfRangeException("index", "< 0");
}
if (count < 0)
{
throw new ArgumentOutOfRangeException("count", "< 0");
}
if (index > buffer.Length - count)
{
throw new ArgumentException("index + count > buffer.Length");
}
this.internalString.Append(buffer, index, count);
}
// Token: 0x04000721 RID: 1825
private StringBuilder internalString;
// Token: 0x04000722 RID: 1826
private bool disposed;
}
}