Why does XmlWriter.Create have output parameters?

  softwareengineering

Why does XmlWriter’s create methods have output parameters?

For example (from MSDN)

public static XmlWriter Create(
    StringBuilder output,
    XmlWriterSettings settings
)

output 
  Type: System.Text.StringBuilder 
  The StringBuilder to which to write to.
  Content written by the XmlWriter is appended to the StringBuilder.

Why doesn’t create not take the StringBuilder and instead of Flush have toString or toStream or toStringBuilder if thats whats really wanted.

I’m not asking how to use XmlWriter, I’m trying to understand the reasoning why it was constructed this way. I assume there is a reason, or even it to be a known pattern with advantages and disadvantages, I’d like to know more about this

3

That’s not an “output” parameter (even though it’s called “output”); it’s just a reference to a StringBuilder.

Why doesn’t create not take the StringBuilder and instead of Flush have toString or toStream or toStringBuilder if thats whats really wanted.

Because it uses the StringBuilder during the writing process.

2

LEAVE A COMMENT