471,601 Members | 1,226 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,601 software developers and data experts.

TextReader is missing Encoding property, why?

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.
Oct 19 '07 #1
1 6106
On Oct 19, 3:11 pm, "Rene" <a...@b.comwrote:
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

Oct 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Alberto Grosso Nicolin | last post: by
3 posts views Thread by Chan | last post: by
2 posts views Thread by Bryan Dickerson | last post: by
reply views Thread by Jigar.Patel | last post: by
4 posts views Thread by Terry Olsen | last post: by
4 posts views Thread by Christina | last post: by
7 posts views Thread by =?Utf-8?B?QU9UWCBTYW4gQW50b25pbw==?= | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.