TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > C#(C Sharp)

Notices

Reply
 
Thread Tools Display Modes
Old 19-10-2007, 09:32 PM   #1
Rene
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.


  Reply With Quote
Old 19-10-2007, 11:32 PM   #2
Jon Skeet [C# MVP]
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

  Reply With Quote
Reply

Thread Tools
Display Modes




New To Site? Need Help?

All times are GMT +5.5. The time now is 03:08 PM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional