FastStringWriter
Namespace: SnowBank.IO · class
Implements: TextWriter, IDisposable, IAsyncDisposable
"Fast" version of StringWriter, that performs fewer checks, but is a good fit for specific use cases (serialization, ...)
Remarks
This type is "unsafe" and should only be used internally, and not exposed to the caller.
Constructors
FastStringWriter
FastStringWriter()
FastStringWriter(int capacity)
FastStringWriter(StringBuilder buffer)
Properties
Buffer
StringBuilder Buffer { get; }
Encoding
Encoding Encoding { get; }
Methods
Close
void Close()
CopyTo
void CopyTo(TextWriter output, char[] buffer = null)
Copy the content of the buffer to another text writer
output— Writer where to write the content of the bufferbuffer— Optional buffer used for the copy (if notnull)
Perform an "optimized" copy by preventing the string allocation from the inner StringBuilder
FlushAsync
Task FlushAsync()
GetBytes
byte[] GetBytes(Encoding encoding)
Return the content of the buffer, as bytes, using the specified encoding
encoding— Encoding used to convert text into bytes (ex: Encoding.UTF8)
Returns: Content of the buffer, encoded into bytes
GetStringBuilder
StringBuilder GetStringBuilder()
Return the underlying buffer used by this writer
Reset
void Reset()
ToCharArray
char[] ToCharArray()
Return the current buffer as an array of char
Returns: Text that has been written so far
Caution: please don't call this method if more text will be written later, because it will cause a lot of extra memory allocations!
ToString
string ToString()
Return the current buffer as a string
Returns: Text that has been written so far
Caution: please don't call this method if more text will be written later, because it will cause a lot of extra memory allocations!
Write
void Write(char value)
void Write(string value)
void Write(char[] value)
void Write(int value)
void Write(long value)
void Write(ReadOnlySpan<char> buffer)
void Write(char[] buffer, int index, int count)
WriteAsync
Task WriteAsync(string value)
Task WriteAsync(char value)
Task WriteAsync(StringBuilder value, CancellationToken cancellationToken = null)
Task WriteAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = null)
Task WriteAsync(char[] value, int index, int count)
WriteLine
void WriteLine()
void WriteLine(char value)
void WriteLine(string value)
void WriteLine(ReadOnlySpan<char> buffer)
void WriteLine(char[] buffer, int index, int count)