internal static string ReadToString(this Stream source)
{
if (!source.CanRead)
throw new InvalidOperationException("Cannot read from source stream.");
if (!source.CanSeek)
throw new InvalidOperationException("Cannot seek from source stream.");
long position = source.Position;
using (StreamReader sr = new StreamReader(source))
{
string result = sr.ReadToEnd();
source.Seek(position, SeekOrigin.Begin);
return result;
}
}