Pregunta

Here's the documentation for the method XContainer.CreateWriter:

Creates an XmlWriter that can be used to add nodes to the XContainer.

I parse the text with my mind, I get:

  • A method implemented by the class XContainer
  • Returns an instance of the class XmlWriter
  • The purpose is to add nodes to the instance of the XContainer on which the method is called.

However, I see XmlWriter, and I think of "writing XML". But that contradicts the above purpose in my mind, which is to add nodes. If I'm going to be adding nodes, wouldn't a "reader" be the thing I use to do so?

I'm not claiming anything is wrong other than my confusion here. I'd like assistance in grasping the apropriate metaphor so I can keep this straight in the future.

How is the naming convention used in Readers/Writers related to thier functionality in .NET framework classes?

¿Fue útil?

Solución

Reading involves no modification to the data structure. That's why you have read-only access which means that no modification can be made.

In your case you will be modifying the data structure (adding nodes) therefore you're not only reading but also writing (those new nodes).

PS. Your second bullet point is not entirely true. The method can return the class that derives from XmlWriter, too.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top