TextReader is missing Encoding property, why?

  • Thread starter Thread starter Rene
  • Start date Start date
R

Rene

Hi,

I decided to take a closer look at the TextWriter and TextReader abstract
classes just for fun.

While poking around, I noticed that the TextWriter class includes an
'Encoding' property in its definition. To me, this sounds very logical
because the TextWriter is all about writing text and sooner or later you
will need to use a type of encoding that specifies how to write (persist)
the text.

On the other hand, the TextReader does not include an Encoding property in
its definition. To me, this is not logical because since the TextReader is
also all about reading text, I would think that sooner or later you will
need to know what encoding to use when translating (reading) the source info
into text.

So the question is, could someone enlighten me as to why the TextWriter
include and Encoding property on its definition but the TextReader does not?

Thank you.
 
I decided to take a closer look at the TextWriter and TextReader abstract
classes just for fun.

While poking around, I noticed that the TextWriter class includes an
'Encoding' property in its definition. To me, this sounds very logical
because the TextWriter is all about writing text and sooner or later you
will need to use a type of encoding that specifies how to write (persist)
the text.

Well, that may or may not need to be known internally (it's not
relevant to what StringWriter does for instance) but it *is* needed by
other things, in particular when writing XML - you need to know which
encoding to specify *within* the encoded text.
On the other hand, the TextReader does not include an Encoding property in
its definition. To me, this is not logical because since the TextReader is
also all about reading text, I would think that sooner or later you will
need to know what encoding to use when translating (reading) the source info
into text.

The TextReader may know it internally - StreamReader does, for
instance - but why would a *client* need to know it? For other string
readers which don't need any translation (e.g. StringReader) it
wouldn't make sense.
So the question is, could someone enlighten me as to why the TextWriter
include and Encoding property on its definition but the TextReader does not?

I suspect TextWriter has it specifically for XML reasons - I can't say
I've seen it used outside that situation.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top