Is it possible to create an extension method similar to this? How should I handle Closing() the stream when finished?
public static TextReader ToTextReader(this string XML)
{
StringReader sr = new StringReader(XML);
return sr;
}
You don’t need to; when the calling code closes the
TextReader(as it should), theStreamis automatically closed as well. There’s no need to close both objects individually.