[Serializable] |
By default, a TextWriter is not thread safe. See TextWriter.Synchronized for a thread-safe wrapper.
A derived class must minimally implement the Write (Char) method in order to make a useful instance of TextWriter.
Null |
Encoding | Read-only When overridden in a derived class, returns the Encoding in which the output is written. |
FormatProvider | Read-only Gets an object that controls formatting. |
NewLine | Read-write Gets or sets the line terminator string used by the current TextWriter. |
Close | Closes the current writer and releases any system resources associated with the writer. |
CreateObjRef (inherited from System.MarshalByRefObject) |
See base class member description: System.MarshalByRefObject.CreateObjRef Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
Flush | Clears all buffers for the current writer and causes any buffered data to be written to the underlying device. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetLifetimeService (inherited from System.MarshalByRefObject) |
See base class member description: System.MarshalByRefObject.GetLifetimeService Retrieves the current lifetime service object that controls the lifetime policy for this instance. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
InitializeLifetimeService (inherited from System.MarshalByRefObject) |
See base class member description: System.MarshalByRefObject.InitializeLifetimeService Obtains a lifetime service object to control the lifetime policy for this instance. |
Synchronized | Creates a thread-safe wrapper around the specified TextWriter. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
Write | Overloaded:Write(bool value) Writes the text representation of a Boolean value to the text stream. |
Write | Overloaded:Write(char value) Writes a character to the text stream. |
Write | Overloaded:Write(char[] buffer) Writes a character array to the text stream. |
Write | Overloaded:Write(decimal value) Writes the text representation of a decimal value followed by a line terminator to the text stream. |
Write | Overloaded:Write(double value) Writes the text representation of an 8-byte floating-point value to the text stream. |
Write | Overloaded:Write(int value) Writes the text representation of a 4-byte signed integer to the text stream. |
Write | Overloaded:Write(long value) Writes the text representation of an 8-byte signed integer to the text stream. |
Write | Overloaded:Write(object value) Writes the text representation of an object to the text stream by calling ToString on that object. |
Write | Overloaded:Write(float value) Writes the text representation of a 4-byte floating-point value to the text stream. |
Write | Overloaded:Write(string value) Writes a string to the text stream. |
Write | Overloaded:Write(uint value) Writes the text representation of a 4-byte unsigned integer to the text stream. |
Write | Overloaded:Write(ulong value) Writes the text representation of an 8-byte unsigned integer to the text stream. |
Write | Overloaded:Write(string format, object arg0) Writes out a formatted string, using the same semantics as String.Format. |
Write | Overloaded:Write(string format, params object[] arg) Writes out a formatted string, using the same semantics as String.Format. |
Write | Overloaded:Write(char[] buffer, int index, int count) Writes a subarray of characters to the text stream. |
Write | Overloaded:Write(string format, object arg0, object arg1) Writes out a formatted string, using the same semantics as String.Format. |
Write | Overloaded:Write(string format, object arg0, object arg1, object arg2) Writes out a formatted string, using the same semantics as String.Format. |
WriteLine | Overloaded:WriteLine() Writes a line terminator to the text stream. |
WriteLine | Overloaded:WriteLine(bool value) Writes the text representation of a Boolean followed by a line terminator to the text stream. |
WriteLine | Overloaded:WriteLine(char value) Writes a character followed by a line terminator to the text stream. |
WriteLine | Overloaded:WriteLine(char[] buffer) Writes an array of characters followed by a line terminator to the text stream. |
WriteLine | Overloaded:WriteLine(decimal value) Writes the text representation of a decimal value followed by a line terminator to the text stream. |
WriteLine | Overloaded:WriteLine(double value) Writes the text representation of a 8-byte floating-point value followed by a line terminator to the text stream. |
WriteLine | Overloaded:WriteLine(int value) Writes the text representation of a 4-byte signed integer followed by a line terminator to the text stream. |
WriteLine | Overloaded:WriteLine(long value) Writes the text representation of an 8-byte signed integer followed by a line terminator to the text stream. |
WriteLine | Overloaded:WriteLine(object value) Writes the text representation of an object by calling ToString on this object, followed by a line terminator to the text stream. |
WriteLine | Overloaded:WriteLine(float value) Writes the text representation of a 4-byte floating-point value followed by a line terminator to the text stream. |
WriteLine | Overloaded:WriteLine(string value) Writes a string followed by a line terminator to the text stream. |
WriteLine | Overloaded:WriteLine(uint value) Writes the text representation of a 4-byte unsigned integer followed by a line terminator to the text stream. |
WriteLine | Overloaded:WriteLine(ulong value) Writes the text representation of an 8-byte unsigned integer followed by a line terminator to the text stream. |
WriteLine | Overloaded:WriteLine(string format, object arg0) Writes out a formatted string and a new line, using the same semantics as String.Format. |
WriteLine | Overloaded:WriteLine(string format, params object[] arg) Writes out a formatted string and a new line, using the same semantics as String.Format. |
WriteLine | Overloaded:WriteLine(char[] buffer, int index, int count) Writes a subarray of characters followed by a line terminator to the text stream. |
WriteLine | Overloaded:WriteLine(string format, object arg0, object arg1) Writes out a formatted string and a new line, using the same semantics as String.Format. |
WriteLine | Overloaded:WriteLine(string format, object arg0, object arg1, object arg2) Writes out a formatted string and a new line, using the same semantics as String.Format. |
ctor #1 | Overloaded:.ctor() Default constructor. This constructor is called by derived class constructors to initialize state in this type. |
ctor #2 | Overloaded:.ctor(IFormatProvider formatProvider) Initializes a new instance of the TextWriter class with the specified format provider. |
CoreNewLine | Stores the new line characters used for this TextWriter. |
Dispose | Releases the unmanaged resources used by the TextWriter and optionally releases the managed resources. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
protected TextWriter(); |
protected TextWriter( |
formatProvider
protected char[] CoreNewLine;
|
public static readonly TextWriter Null;
|
When the TextWriter.Write methods are invoked on Null, the call simply returns, and no data is actually written to any backing store.
public abstract Encoding Encoding {get;}
|
public virtual IFormatProvider FormatProvider {get;}
|
public virtual string NewLine {get; set;}
|
The line terminator string is written to the text stream whenever one of the WriteLine methods is called. In order for text written by the TextWriter to be readable by a TextReader, only "\n" or "\r\n" should be used as terminator strings. If NewLine is set to null, the default newline character is used instead.
public virtual void Close(); |
Flushing the stream will not flush its underlying encoder unless you explicitly call TextWriter.Flush or Close. Setting StreamWriter.AutoFlush to true means that data will be flushed from the buffer to the stream, but the encoder state will not be flushed. This allows the encoder to keep its state (partial characters) so that it can encode the next block of characters correctly. This scenario affects UTF8 and UTF7 where certain characters can only be encoded after the encoder receives the adjacent character or characters.
Following a call to Close, any operations on the writer might raise exceptions. This default method does nothing, but derived classes can override the method to provide the appropriate functionality.
requestedType
Exception Type | Condition |
---|---|
RemotingException | This instance is not a valid remoting object. |
protected virtual void Dispose( |
disposing
When the disposing parameter is true, this method releases all resources held by any managed objects that this TextWriter references. This method invokes the Dispose() method of each referenced object.
For more information about Dispose and Object.Finalize, see the conceptual topic at MSDN: cleaningupunmanagedresources and the conceptual topic at MSDN: overridingfinalizemethod.
~TextWriter(); |
public virtual void Flush(); |
Flushing the stream will not flush its underlying encoder unless you explicitly call Flush or TextWriter.Close. Setting StreamWriter.AutoFlush to true means that data will be flushed from the buffer to the stream, but the encoder state will not be flushed. This allows the encoder to keep its state (partial characters) so that it can encode the next block of characters correctly. This scenario affects UTF8 and UTF7 where certain characters can only be encoded after the encoder receives the adjacent character or characters.
public virtual int GetHashCode(); |
public object GetLifetimeService(); |
public Type GetType(); |
public virtual object InitializeLifetimeService(); |
public class MyClass : MarshalByRefObject { public override Object InitializeLifetimeService() { ILease lease = (ILease)base.InitializeLifetimeService(); if (lease.CurrentState == LeaseState.Initial) { lease.InitialLeaseTime = TimeSpan.FromMinutes(1); lease.SponsorshipTimeout = TimeSpan.FromMinutes(2); lease.RenewOnCallTime = TimeSpan.FromSeconds(2); } return lease; } }
protected object MemberwiseClone(); |
public static TextWriter Synchronized( |
writer
Exception Type | Condition |
---|---|
ArgumentNullException | writer is null. |
public virtual string ToString(); |
public virtual void Write( |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
This method outputs either Boolean.TrueString or Boolean.FalseString.
public virtual void Write( |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
public virtual void Write( |
buffer
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
This default method calls Write (char[], int, int) and passes the entire character array. If the character array is null, nothing is written.
public virtual void Write( |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs. |
public virtual void Write( |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
public virtual void Write( |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
public virtual void Write( |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
public virtual void Write( |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
If the specified object is null, no action is taken and no exception is thrown. Otherwise, the object's ToString method is called to produce the string representation, and the resulting string is then written to the output stream.
public virtual void Write( |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
public virtual void Write( |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
This method does not search the specified String for individual newline characters(hexadecimal 0x000a) and replace them with TextWriter.NewLine.
If value is null, nothing is written to the text stream.
[CLSCompliant(false)] |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
[CLSCompliant(false)] |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
format
arg0
Exception Type | Condition |
---|---|
ArgumentNullException | format or arg0 is null. -or- An object referenced in the format string is null. |
IOException | An I/O error occurs, such as the stream being closed. |
FormatException | The format specification in format is invalid. -or- The number indicating an argument to be formatted is less than zero, or larger than or equal to the number of provided objects to be formatted . |
This method does not search the specified String for individual newline characters(hexadecimal 0x000a) and replace them with TextWriter.NewLine.
If a specified object is not referenced in the format string, it is ignored.
format
arg
Exception Type | Condition |
---|---|
ArgumentNullException | format or arg is null. |
IOException | An I/O error occurs, such as the stream being closed. |
FormatException | The format specification in format is invalid. -or- The number indicating an argument to be formatted is less than zero, or larger than or equal to arg.Length. |
This method does not search the specified String for individual newline characters(hexadecimal 0x000a) and replace them with TextWriter.NewLine.
If a specified object is not referenced in the format string, it is ignored.
buffer
index
count
Exception Type | Condition |
---|---|
ArgumentException | The buffer length minus index is less than count. |
ArgumentNullException | The buffer parameter is Null. |
ArgumentOutOfRangeException | index or count is negative. |
IOException | An I/O error occurs, such as the stream being closed. |
This version of TextWriter.Write is equivalent to (buffer[i]) for each character in buffer between index and (index + count).
format
arg0
arg1
Exception Type | Condition |
---|---|
ArgumentNullException | format or any of the arg parameters is null. -or- An object referenced in the format string is null. |
IOException | An I/O error occurs, such as the stream being closed. |
FormatException | The format specification in format is invalid. -or- The number indicating an argument to be formatted is less than zero, or larger than or equal to the number of provided objects to be formatted . |
This method does not search the specified String for individual newline characters(hexadecimal 0x000a) and replace them with TextWriter.NewLine.
If a specified object is not referenced in the format string, it is ignored.
format
arg0
arg1
arg2
Exception Type | Condition |
---|---|
ArgumentNullException | format or any of the arg parameters is null. -or- An object referenced in the format string is null. |
IOException | An I/O error occurs, such as the stream being closed. |
FormatException | The format specification in format is invalid. -or- The number indicating an argument to be formatted is less than zero, or larger than or equal to the number of provided objects to be formatted . |
This method does not search the specified String for individual newline characters(hexadecimal 0x000a) and replace them with TextWriter.NewLine.
If a specified object is not referenced in the format string, it is ignored.
public virtual void WriteLine(); |
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
public virtual void WriteLine( |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
This method outputs either Boolean.TrueString or Boolean.FalseString.
public virtual void WriteLine( |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
public virtual void WriteLine( |
buffer
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
This version of TextWriter.WriteLine is equivalent to (buffer) followed by ().
public virtual void WriteLine( |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs. |
public virtual void WriteLine( |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
public virtual void WriteLine( |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
public virtual void WriteLine( |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
public virtual void WriteLine( |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
public virtual void WriteLine( |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
public virtual void WriteLine( |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
The line terminator string is defined by the TextWriter.NewLine property.
This method does not search the specified String for individual newline characters(hexadecimal 0x000a) and replace them with TextWriter.NewLine.
[CLSCompliant(false)] |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
[CLSCompliant(false)] |
value
Exception Type | Condition |
---|---|
IOException | An I/O error occurs, such as the stream being closed. |
format
arg0
Exception Type | Condition |
---|---|
ArgumentNullException | A string or object is passed in as null. -or- An object referenced in the format string is null. |
IOException | An I/O error occurs, such as the stream being closed. |
FormatException | The format specification in format is invalid. -or- The number indicating an argument to be formatted is less than zero, or larger than or equal to the number of provided objects to be formatted . |
This method does not search the specified String for individual newline characters(hexadecimal 0x000a) and replace them with TextWriter.NewLine.
If a specified object is not referenced in the format string, it is ignored.
format
arg
Exception Type | Condition |
---|---|
ArgumentNullException | A string or object is passed in as null. |
IOException | An I/O error occurs, such as the stream being closed. |
FormatException | The format specification in format is invalid. -or- The number indicating an argument to be formatted is less than zero, or larger than or equal to arg.Length. |
This method does not search the specified String for individual newline characters(hexadecimal 0x000a) and replace them with TextWriter.NewLine.
If a specified object is not referenced in the format string, it is ignored.
buffer
index
count
Exception Type | Condition |
---|---|
ArgumentException | The buffer length minus index is less than count. |
ArgumentNullException | The buffer parameter is Null. |
ArgumentOutOfRangeException | index or count is negative. |
IOException | An I/O error occurs, such as the stream being closed. |
This method does not search the specified String for individual newline characters(hexadecimal 0x000a) and replace them with TextWriter.NewLine.
This version of TextWriter.WriteLine is equivalent to (buffer[i]) for each character in buffer between index and (index + count) followed by ().
format
arg0
arg1
Exception Type | Condition |
---|---|
ArgumentNullException | A string or object is passed in as null. -or- An object referenced in the format string is null. |
IOException | An I/O error occurs, such as the stream being closed. |
FormatException | The format specification in format is invalid. -or- The number indicating an argument to be formatted is less than zero, or larger than or equal to the number of provided objects to be formatted. |
This method does not search the specified String for individual newline characters(hexadecimal 0x000a) and replace them with TextWriter.NewLine.
If a specified object is not referenced in the format string, it is ignored.
format
arg0
arg1
arg2
Exception Type | Condition |
---|---|
ArgumentNullException | A string or object is passed in as null. -or- An object referenced in the format string is null. |
IOException | An I/O error occurs, such as the stream being closed. |
FormatException | The format specification in format is invalid. -or- The number indicating an argument to be formatted is less than zero, or larger than or equal to the number of provided objects to be formatted. |
This method does not search the specified String for individual newline characters(hexadecimal 0x000a) and replace them with TextWriter.NewLine.
If a specified object is not referenced in the format string, it is ignored.