+ // Get the number of bytes needed to encode a character buffer.
+ public unsafe override int GetByteCountImpl (char* chars, int count)
+ {
+ if (this.EncoderFallback != null) {
+ //Calculate byte count by actually doing encoding and discarding the data.
+ return GetBytesImpl(chars, count, null, 0);
+ }
+ else
+
+ {
+ return count;
+ }
+ }
+
+ // Get the number of bytes needed to encode a character buffer.
+ public override int GetByteCount (String s)
+ {
+ if (this.EncoderFallback != null)
+ {
+ //Calculate byte count by actually doing encoding and discarding the data.
+ unsafe
+ {
+ fixed (char *s_ptr = s)
+ {
+ return GetBytesImpl(s_ptr, s.Length, null, 0);
+ }
+ }
+ }
+ else
+ {
+ //byte count equals character count because no EncoderFallback set
+ return s.Length;
+ }
+ }
+
+ //ToBytes is just an alias for GetBytesImpl, but doesn't return byte count
+ protected unsafe override void ToBytes(char* chars, int charCount,
+ byte* bytes, int byteCount)
+ {
+ //Calling ToBytes with null destination buffer doesn't make any sense
+ if (bytes == null)
+ throw new ArgumentNullException("bytes");
+ GetBytesImpl(chars, charCount, bytes, byteCount);
+ }
+
+ public unsafe override int GetBytesImpl (char* chars, int charCount,
+ byte* bytes, int byteCount)