[Serializable] |
By default, a TextReader is not thread safe. See TextReader.Synchronized for a thread-safe wrapper.
A derived class must minimally implement the TextReader.Peek and TextReader.Read methods in order to make a useful instance of TextReader.
Null | Provides a TextReader with no data to read from. |
Close | Closes the TextReader and releases any system resources associated with the TextReader. |
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. |
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. |
Peek | Reads the next character without changing the state of the reader or the character source.Returns the next available character without actually reading it from the input stream. |
Read | Overloaded:Read() Reads the next character from the input stream and advances the character position by one character. |
Read | Overloaded:Read(in char[] buffer, int index, int count) Reads a maximum of count characters from the current stream and writes the data to buffer, beginning at index. |
ReadBlock | Reads a maximum of count characters from the current stream and writes the data to buffer, beginning at index. |
ReadLine | Reads a line of characters from the current stream and returns the data as a string. |
ReadToEnd | Reads all characters from the current position to the end of the TextReader and returns them as one string. |
Synchronized | Creates a thread-safe wrapper around the specified TextReader. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
ctor #1 | Default constructor. This constructor is called by derived class constructors to initialize state in this type. |
Dispose | Releases the unmanaged resources used by the TextReader 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 TextReader(); |
public static readonly TextReader Null;
|
TextReader.Read and TextReader.Peek methods return -1
TextReader.ReadBlock method returns zero
TextReader.ReadLine and TextReader.ReadToEnd methods return null
public virtual void Close(); |
Flushing the stream will not flush its underlying encoder unless you explicitly call 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 TextReader might throw exceptions. This default method is empty, 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 TextReader 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.
~TextReader(); |
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 virtual int Peek(); |
Exception Type | Condition |
---|---|
IOException | An I/O error occurs. |
public virtual int Read(); |
Exception Type | Condition |
---|---|
IOException | An I/O error occurs. |
buffer
index
count
Exception Type | Condition |
---|---|
ArgumentNullException | buffer is null. |
ArgumentException | The buffer length minus index is less than count. |
ArgumentOutOfRangeException | index or count is negative. |
IOException | An I/O error occurs. |
buffer
index
count
Exception Type | Condition |
---|---|
ArgumentNullException | buffer is null. |
ArgumentException | The buffer length minus index is less than count. |
ArgumentOutOfRangeException | index or count is negative. |
IOException | An I/O error occurs. |
public virtual string ReadLine(); |
Exception Type | Condition |
---|---|
IOException | An I/O error occurs. |
OutOfMemoryException | There is insufficient memory to allocate a buffer for the returned string. |
ArgumentOutOfRangeException | The number of characters in the next line is larger than Int32.MaxValue |
If the current method throws an OutOfMemoryException, the reader's position in the underlying Stream is advanced by the number of characters the method was able to read, but the characters already read into the internal TextReader.ReadLine buffer are discarded. Since the position of the reader in the stream cannot be changed, the characters already read are unrecoverable, and can be accessed only by reinitializing the TextReader. If the initial position within the stream is unknown or the stream does not support seeking, the underlying Stream also needs to be reinitialized.
To avoid such a situation and produce robust code you should use the TextReader.Read method and store the read characters in a preallocated buffer.
public virtual string ReadToEnd(); |
Exception Type | Condition |
---|---|
IOException | An I/O error occurs. |
OutOfMemoryException | There is insufficient memory to allocate a buffer for the returned string. |
ArgumentOutOfRangeException | The number of characters in the next line is larger than Int32.MaxValue |
To avoid such a situation and produce robust code you should use the TextReader.Read method and store the read characters in a preallocated buffer.
public static TextReader Synchronized( |
reader
Exception Type | Condition |
---|---|
ArgumentNullException | reader is null. |
public virtual string ToString(); |