/// <summary> /// Get maximum char count needed to decode the entire stream. /// </summary> /// <param name="encoding"></param> /// <param name="stream"></param> /// <exception cref="IOException">Stream is so big that max char count can't fit in <see cref="int"/>.</exception> public static int GetMaxCharCountOrThrowIfHuge(this Encoding encoding, Stream stream) { Debug.Assert(stream.CanSeek); long length = stream.Length; int maxCharCount; if (encoding.TryGetMaxCharCount(length, out maxCharCount)) { return(maxCharCount); } #if WORKSPACE throw new IOException(WorkspacesResources.Stream_is_too_long); #else throw new IOException(); #endif }