X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem.IO%2FStringReader.cs;h=f59d58d177a4ce6330395dbca30772ff0d5dc3ba;hb=0bd44175328422f8e070c7da5f5c19092a2ea129;hp=b66167d910ba6195b4642998de3672192399f52c;hpb=98a86ecd4ba2d3b4631d98ac5a4abf23f4e6c3e3;p=mono.git diff --git a/mcs/class/corlib/System.IO/StringReader.cs b/mcs/class/corlib/System.IO/StringReader.cs index b66167d910b..f59d58d177a 100644 --- a/mcs/class/corlib/System.IO/StringReader.cs +++ b/mcs/class/corlib/System.IO/StringReader.cs @@ -35,14 +35,14 @@ using System.Runtime.InteropServices; namespace System.IO { [Serializable] +#if NET_2_0 + [ComVisible (true)] +#endif public class StringReader : TextReader { - private string source; - private char[] sourceChars; - - private int nextChar; - private int sourceLength; - private bool disposed = false; + string source; + int nextChar; + int sourceLength; public StringReader( string s ) { @@ -52,17 +52,16 @@ namespace System.IO { this.source = s; nextChar = 0; sourceLength = s.Length; - sourceChars = s.ToCharArray(); } - public override void Close() { - Dispose( true ); - disposed = true; + public override void Close () + { + Dispose (true); } protected override void Dispose (bool disposing) { - sourceChars = null; + source = null; base.Dispose (disposing); } @@ -94,28 +93,26 @@ namespace System.IO { // the actual number of characters read, or zero if the end of the string // has been reached and no characters are read. - public override int Read ([In, Out] char[] buffer, int index, int count ) + public override int Read ([In, Out] char[] buffer, int index, int count) { CheckObjectDisposedException (); - if( buffer == null ) { + if (buffer == null) throw new ArgumentNullException ("buffer"); - } else if( buffer.Length - index < count ) { - throw new ArgumentException(); - } else if( index < 0 || count < 0 ) { - throw new ArgumentOutOfRangeException(); - } + if (buffer.Length - index < count) + throw new ArgumentException (); + if (index < 0 || count < 0) + throw new ArgumentOutOfRangeException (); int charsToRead; // reordered to avoir possible integer overflow - if (nextChar > sourceLength - count) { + if (nextChar > sourceLength - count) charsToRead = sourceLength - nextChar; - } else { + else charsToRead = count; - } - - Array.Copy(sourceChars, nextChar, buffer, index, charsToRead ); + + source.CopyTo (nextChar, buffer, index, charsToRead); nextChar += charsToRead; @@ -175,10 +172,9 @@ namespace System.IO { private void CheckObjectDisposedException () { - if (disposed) { + if (source == null) throw new ObjectDisposedException ("StringReader", Locale.GetText ("Cannot read from a closed StringReader")); - } } } }