473,804 Members | 3,469 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6200
On Oct 19, 3:11 pm, "Rene" <a...@b.comwrot e:
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
519
by: | last post by:
I am rewriting a C++ application in C#. This file has a combination of Text and Binary data. I used CFile before to read the text. If I hit a certain string that denotes the following data is binary, I used the current position in the file and another stream to read to the binary data. All text data is ended with a carriage return / line feed while the binary is actually an image file listed byte by byte. Preceding the binary data...
0
1708
by: Alberto Grosso Nicolin | last post by:
We have the following XML schema: there's a root element (Response) with of a single child element (Result). ---------------------------------------------------------------------------------------------- <?xml version="1.0" encoding="utf-8"?> <xs:schema id="TaskRequest" targetNamespace="http://xyz.com/TaskResponse/1.0" elementFormDefault="qualified" xmlns="http://xyz.com/TaskResponse/1.0"
3
1460
by: Chan | last post by:
Got in a difficult situation of storing and retrieving TextReader in Cache, but found no such post yet. Tried to store a textreader into Cache object in a similar way illustrated in .NET's SDK doc ("Retrieving Values of Cached Items"): ' ----------------------------- ... Dim CPCache As textreader = CType(Cache("CP"), textreader) If CPCache Is Nothing Then ...
2
16309
by: Bryan Dickerson | last post by:
StreamReader says it is designed to read a stream of characters StringReader says it is designed to read a string TextReader says it is designed to read a sequential list of characters. I hate to sound like a VB6 grump, but aren't we splitting hairs?? What's the difference? -- TFWBWY...A
0
1989
by: Jigar.Patel | last post by:
I have simple remoting server exposing following simple method. When I try to add webreference to this server in another project by serveraddresss?wsdl, it gives me following error: Custom tool error: Unable to import WebService/Schema. Unable to import binding 'MyRemoteObjectBinding' from namespace...
0
4850
by: Jigar.Patel | last post by:
I have simple remoting server exposing following simple method. When I try to add webreference to this server in another project, it gives me following error: Custom tool error: Unable to import WebService/Schema. Unable to import binding 'MyRemoteObjectBinding' from namespace 'http://schemas.microsoft.com/clr/nsassem/RemoteServer/RemoteServer%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull'. Unable to import...
4
1884
by: Terry Olsen | last post by:
I use the following code to create an XML string: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim tw As New StringWriter Dim xml As New XmlTextWriter(tw) xml.WriteStartDocument() xml.WriteStartElement("StartElement") xml.WriteElementString("ElementString", "TheElement") xml.WriteEndElement()
4
8384
by: Christina | last post by:
Hey Guys, Currently, I am using the below code: Dim oReqDoc as XmlDocument Dim requiredBytes As Byte() requiredBytes = System.Text.UTF8Encoding.UTF8.GetBytes(oReqDoc.InnerXml). Here, I am encoding my xml string in UTF8 format.
7
2834
by: =?Utf-8?B?QU9UWCBTYW4gQW50b25pbw==?= | last post by:
Hi, I have been using the code (some of it has been removed for simplicity) below to allow authenticated (using ASP.NET membership database) users to get a file from their archive area. It seems to work fine, however I noticed that no web log entry is added when a successful download occurs (normally a 200 HTTP status code, however, if there is an authorization failure, it gets logged). I have a logging routine that logs a successful...
0
9708
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10589
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10327
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.