Merge pull request #1179 from ludovic-henry/pr25-threadpool
[mono.git] / mcs / class / corlib / System.Text / Decoder.cs
index d00dc4841595e6a3fd3932115b6f1d1d493e6e13..c44176989c8acdac1df35754ad32cffbc069bf14 100644 (file)
@@ -29,16 +29,17 @@ using System;
 using System.Runtime.InteropServices;
 
 [Serializable]
+[ComVisible (true)]
 public abstract class Decoder
 {
 
        // Constructor.
        protected Decoder () {}
 
-#if NET_2_0
        DecoderFallback fallback = new DecoderReplacementFallback ();
        DecoderFallbackBuffer fallback_buffer;
 
+       [ComVisible (false)]
        public DecoderFallback Fallback {
                get { return fallback; }
                set {
@@ -49,6 +50,7 @@ public abstract class Decoder
                }
        }
 
+       [ComVisible (false)]
        public DecoderFallbackBuffer FallbackBuffer {
                get {
                        if (fallback_buffer == null)
@@ -56,7 +58,6 @@ public abstract class Decoder
                        return fallback_buffer;
                }
        }
-#endif
 
        // Get the number of characters needed to decode a buffer.
        public abstract int GetCharCount (byte[] bytes, int index, int count);
@@ -65,7 +66,7 @@ public abstract class Decoder
        public abstract int GetChars (byte[] bytes, int byteIndex, int byteCount,
                                                                 char[] chars, int charIndex);
 
-#if NET_2_0
+       [ComVisible (false)]
        public virtual int GetCharCount (byte [] bytes, int index, int count, bool flush)
        {
                if (flush)
@@ -74,6 +75,7 @@ public abstract class Decoder
        }
 
        [CLSCompliant (false)]
+       [ComVisible (false)]
        public unsafe virtual int GetCharCount (byte* bytes, int count, bool flush)
        {
                if (bytes == null)
@@ -99,18 +101,21 @@ public abstract class Decoder
        }
 
        [CLSCompliant (false)]
+       [ComVisible (false)]
        public unsafe virtual int GetChars (byte* bytes, int byteCount,
                char* chars, int charCount, bool flush)
        {
                CheckArguments (chars, charCount, bytes, byteCount);
 
                char [] carr = new char [charCount];
-               Marshal.Copy ((IntPtr) chars, carr, 0, charCount);
                byte [] barr = new byte [byteCount];
                Marshal.Copy ((IntPtr) bytes, barr, 0, byteCount);
-               return GetChars (barr, 0, byteCount, carr, 0, flush);
+               int charsUsed = GetChars (barr, 0, byteCount, carr, 0, flush);
+               Marshal.Copy (carr, 0, (IntPtr) chars, charsUsed);
+               return charsUsed;
        }
 
+       [ComVisible (false)]
        public virtual void Reset ()
        {
                if (fallback_buffer != null)
@@ -118,6 +123,7 @@ public abstract class Decoder
        }
 
        [CLSCompliant (false)]
+       [ComVisible (false)]
        public unsafe virtual void Convert (
                byte* bytes, int byteCount,
                char* chars, int charCount, bool flush,
@@ -137,13 +143,17 @@ public abstract class Decoder
                charsUsed = GetChars (bytes, bytesUsed, chars, charCount, flush);
        }
 
+       [ComVisible (false)]
        public virtual void Convert (
                byte [] bytes, int byteIndex, int byteCount,
                char [] chars, int charIndex, int charCount, bool flush,
                out int bytesUsed, out int charsUsed, out bool completed)
        {
                CheckArguments (bytes, byteIndex, byteCount);
-               CheckArguments (chars, charIndex);
+               if (chars == null)
+                       throw new ArgumentNullException ("chars");
+               if (charIndex < 0)
+                       throw new ArgumentOutOfRangeException ("charIndex");
                if (charCount < 0 || chars.Length < charIndex + charCount)
                        throw new ArgumentOutOfRangeException ("charCount");
 
@@ -163,7 +173,7 @@ public abstract class Decoder
        {
                if (chars == null)
                        throw new ArgumentNullException ("chars");
-               if (charIndex < 0 || chars.Length <= charIndex)
+               if (charIndex < 0 || chars.Length < charIndex)
                        throw new ArgumentOutOfRangeException ("charIndex");
        }
 
@@ -171,7 +181,7 @@ public abstract class Decoder
        {
                if (bytes == null)
                        throw new ArgumentNullException ("bytes");
-               if (byteIndex < 0 || bytes.Length <= byteIndex)
+               if (byteIndex < 0)
                        throw new ArgumentOutOfRangeException ("byteIndex");
                if (byteCount < 0 || bytes.Length < byteIndex + byteCount)
                        throw new ArgumentOutOfRangeException ("byteCount");
@@ -188,8 +198,6 @@ public abstract class Decoder
                if (byteCount < 0)
                        throw new ArgumentOutOfRangeException ("byteCount");
        }
-#endif
-
 }; // class Decoder
 
 }; // namespace System.Text