![]() |
|
|
#1 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Re: TextReader is missing Encoding property, why?
On Oct 19, 3:11 pm, "Rene" <a...@b.com> wrote:
> 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 |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
| New To Site? | Need Help? |