mscorlib(4.0.0.0) API with additions
UnicodeEncoding.cs
3 using System.Security;
4 
5 namespace System.Text
6 {
9  [ComVisible(true)]
10  [__DynamicallyInvokable]
11  public class UnicodeEncoding : Encoding
12  {
13  [Serializable]
14  private class Decoder : DecoderNLS, ISerializable
15  {
16  internal int lastByte = -1;
17 
18  internal char lastChar;
19 
20  internal override bool HasState
21  {
22  get
23  {
24  if (lastByte == -1)
25  {
26  return lastChar != '\0';
27  }
28  return true;
29  }
30  }
31 
32  public Decoder(UnicodeEncoding encoding)
33  : base(encoding)
34  {
35  }
36 
37  internal Decoder(SerializationInfo info, StreamingContext context)
38  {
39  if (info == null)
40  {
41  throw new ArgumentNullException("info");
42  }
43  lastByte = (int)info.GetValue("lastByte", typeof(int));
44  try
45  {
46  m_encoding = (Encoding)info.GetValue("m_encoding", typeof(Encoding));
47  lastChar = (char)info.GetValue("lastChar", typeof(char));
48  m_fallback = (DecoderFallback)info.GetValue("m_fallback", typeof(DecoderFallback));
49  }
51  {
52  bool bigEndian = (bool)info.GetValue("bigEndian", typeof(bool));
53  m_encoding = new UnicodeEncoding(bigEndian, byteOrderMark: false);
54  }
55  }
56 
57  [SecurityCritical]
59  {
60  if (info == null)
61  {
62  throw new ArgumentNullException("info");
63  }
64  info.AddValue("m_encoding", m_encoding);
65  info.AddValue("m_fallback", m_fallback);
66  info.AddValue("lastChar", lastChar);
67  info.AddValue("lastByte", lastByte);
68  info.AddValue("bigEndian", ((UnicodeEncoding)m_encoding).bigEndian);
69  }
70 
71  public override void Reset()
72  {
73  lastByte = -1;
74  lastChar = '\0';
75  if (m_fallbackBuffer != null)
76  {
77  m_fallbackBuffer.Reset();
78  }
79  }
80  }
81 
82  [OptionalField(VersionAdded = 2)]
83  internal bool isThrowException;
84 
85  internal bool bigEndian;
86 
87  internal bool byteOrderMark = true;
88 
90  public const int CharSize = 2;
91 
93  [__DynamicallyInvokable]
94  public UnicodeEncoding()
95  : this(bigEndian: false, byteOrderMark: true)
96  {
97  }
98 
104  [__DynamicallyInvokable]
105  public UnicodeEncoding(bool bigEndian, bool byteOrderMark)
106  : this(bigEndian, byteOrderMark, throwOnInvalidBytes: false)
107  {
108  }
109 
117  [__DynamicallyInvokable]
118  public UnicodeEncoding(bool bigEndian, bool byteOrderMark, bool throwOnInvalidBytes)
119  : base(bigEndian ? 1201 : 1200)
120  {
121  isThrowException = throwOnInvalidBytes;
122  this.bigEndian = bigEndian;
123  this.byteOrderMark = byteOrderMark;
124  if (isThrowException)
125  {
126  SetDefaultFallbacks();
127  }
128  }
129 
130  [OnDeserializing]
131  private void OnDeserializing(StreamingContext ctx)
132  {
133  isThrowException = false;
134  }
135 
136  internal override void SetDefaultFallbacks()
137  {
138  if (isThrowException)
139  {
140  encoderFallback = EncoderFallback.ExceptionFallback;
141  decoderFallback = DecoderFallback.ExceptionFallback;
142  }
143  else
144  {
145  encoderFallback = new EncoderReplacementFallback("�");
146  decoderFallback = new DecoderReplacementFallback("�");
147  }
148  }
149 
163  [SecuritySafeCritical]
164  [__DynamicallyInvokable]
165  public unsafe override int GetByteCount(char[] chars, int index, int count)
166  {
167  if (chars == null)
168  {
169  throw new ArgumentNullException("chars", Environment.GetResourceString("ArgumentNull_Array"));
170  }
171  if (index < 0 || count < 0)
172  {
173  throw new ArgumentOutOfRangeException((index < 0) ? "index" : "count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
174  }
175  if (chars.Length - index < count)
176  {
177  throw new ArgumentOutOfRangeException("chars", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
178  }
179  if (chars.Length == 0)
180  {
181  return 0;
182  }
183  fixed (char* ptr = chars)
184  {
185  return GetByteCount(ptr + index, count, null);
186  }
187  }
188 
198  [SecuritySafeCritical]
199  [__DynamicallyInvokable]
200  public unsafe override int GetByteCount(string s)
201  {
202  if (s == null)
203  {
204  throw new ArgumentNullException("s");
205  }
206  fixed (char* chars = s)
207  {
208  return GetByteCount(chars, s.Length, null);
209  }
210  }
211 
223  [SecurityCritical]
224  [CLSCompliant(false)]
225  [ComVisible(false)]
226  public unsafe override int GetByteCount(char* chars, int count)
227  {
228  if (chars == null)
229  {
230  throw new ArgumentNullException("chars", Environment.GetResourceString("ArgumentNull_Array"));
231  }
232  if (count < 0)
233  {
234  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
235  }
236  return GetByteCount(chars, count, null);
237  }
238 
257  [SecuritySafeCritical]
258  [__DynamicallyInvokable]
259  public unsafe override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
260  {
261  if (s == null || bytes == null)
262  {
263  throw new ArgumentNullException((s == null) ? "s" : "bytes", Environment.GetResourceString("ArgumentNull_Array"));
264  }
265  if (charIndex < 0 || charCount < 0)
266  {
267  throw new ArgumentOutOfRangeException((charIndex < 0) ? "charIndex" : "charCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
268  }
269  if (s.Length - charIndex < charCount)
270  {
271  throw new ArgumentOutOfRangeException("s", Environment.GetResourceString("ArgumentOutOfRange_IndexCount"));
272  }
273  if (byteIndex < 0 || byteIndex > bytes.Length)
274  {
275  throw new ArgumentOutOfRangeException("byteIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
276  }
277  int byteCount = bytes.Length - byteIndex;
278  if (bytes.Length == 0)
279  {
280  bytes = new byte[1];
281  }
282  fixed (char* ptr = s)
283  {
284  byte[] array = bytes;
285  fixed (byte* ptr2 = array)
286  {
287  return GetBytes(ptr + charIndex, charCount, ptr2 + byteIndex, byteCount, null);
288  }
289  }
290  }
291 
310  [SecuritySafeCritical]
311  [__DynamicallyInvokable]
312  public unsafe override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
313  {
314  if (chars == null || bytes == null)
315  {
316  throw new ArgumentNullException((chars == null) ? "chars" : "bytes", Environment.GetResourceString("ArgumentNull_Array"));
317  }
318  if (charIndex < 0 || charCount < 0)
319  {
320  throw new ArgumentOutOfRangeException((charIndex < 0) ? "charIndex" : "charCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
321  }
322  if (chars.Length - charIndex < charCount)
323  {
324  throw new ArgumentOutOfRangeException("chars", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
325  }
326  if (byteIndex < 0 || byteIndex > bytes.Length)
327  {
328  throw new ArgumentOutOfRangeException("byteIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
329  }
330  if (chars.Length == 0)
331  {
332  return 0;
333  }
334  int byteCount = bytes.Length - byteIndex;
335  if (bytes.Length == 0)
336  {
337  bytes = new byte[1];
338  }
339  fixed (char* ptr = chars)
340  {
341  byte[] array = bytes;
342  fixed (byte* ptr2 = array)
343  {
344  return GetBytes(ptr + charIndex, charCount, ptr2 + byteIndex, byteCount, null);
345  }
346  }
347  }
348 
364  [SecurityCritical]
365  [CLSCompliant(false)]
366  [ComVisible(false)]
367  public unsafe override int GetBytes(char* chars, int charCount, byte* bytes, int byteCount)
368  {
369  if (bytes == null || chars == null)
370  {
371  throw new ArgumentNullException((bytes == null) ? "bytes" : "chars", Environment.GetResourceString("ArgumentNull_Array"));
372  }
373  if (charCount < 0 || byteCount < 0)
374  {
375  throw new ArgumentOutOfRangeException((charCount < 0) ? "charCount" : "byteCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
376  }
377  return GetBytes(chars, charCount, bytes, byteCount, null);
378  }
379 
393  [SecuritySafeCritical]
394  [__DynamicallyInvokable]
395  public unsafe override int GetCharCount(byte[] bytes, int index, int count)
396  {
397  if (bytes == null)
398  {
399  throw new ArgumentNullException("bytes", Environment.GetResourceString("ArgumentNull_Array"));
400  }
401  if (index < 0 || count < 0)
402  {
403  throw new ArgumentOutOfRangeException((index < 0) ? "index" : "count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
404  }
405  if (bytes.Length - index < count)
406  {
407  throw new ArgumentOutOfRangeException("bytes", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
408  }
409  if (bytes.Length == 0)
410  {
411  return 0;
412  }
413  fixed (byte* ptr = bytes)
414  {
415  return GetCharCount(ptr + index, count, null);
416  }
417  }
418 
430  [SecurityCritical]
431  [CLSCompliant(false)]
432  [ComVisible(false)]
433  public unsafe override int GetCharCount(byte* bytes, int count)
434  {
435  if (bytes == null)
436  {
437  throw new ArgumentNullException("bytes", Environment.GetResourceString("ArgumentNull_Array"));
438  }
439  if (count < 0)
440  {
441  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
442  }
443  return GetCharCount(bytes, count, null);
444  }
445 
464  [SecuritySafeCritical]
465  [__DynamicallyInvokable]
466  public unsafe override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
467  {
468  if (bytes == null || chars == null)
469  {
470  throw new ArgumentNullException((bytes == null) ? "bytes" : "chars", Environment.GetResourceString("ArgumentNull_Array"));
471  }
472  if (byteIndex < 0 || byteCount < 0)
473  {
474  throw new ArgumentOutOfRangeException((byteIndex < 0) ? "byteIndex" : "byteCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
475  }
476  if (bytes.Length - byteIndex < byteCount)
477  {
478  throw new ArgumentOutOfRangeException("bytes", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
479  }
480  if (charIndex < 0 || charIndex > chars.Length)
481  {
482  throw new ArgumentOutOfRangeException("charIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
483  }
484  if (bytes.Length == 0)
485  {
486  return 0;
487  }
488  int charCount = chars.Length - charIndex;
489  if (chars.Length == 0)
490  {
491  chars = new char[1];
492  }
493  fixed (byte* ptr = bytes)
494  {
495  char[] array = chars;
496  fixed (char* ptr2 = array)
497  {
498  return GetChars(ptr + byteIndex, byteCount, ptr2 + charIndex, charCount, null);
499  }
500  }
501  }
502 
518  [SecurityCritical]
519  [CLSCompliant(false)]
520  [ComVisible(false)]
521  public unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount)
522  {
523  if (bytes == null || chars == null)
524  {
525  throw new ArgumentNullException((bytes == null) ? "bytes" : "chars", Environment.GetResourceString("ArgumentNull_Array"));
526  }
527  if (charCount < 0 || byteCount < 0)
528  {
529  throw new ArgumentOutOfRangeException((charCount < 0) ? "charCount" : "byteCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
530  }
531  return GetChars(bytes, byteCount, chars, charCount, null);
532  }
533 
547  [SecuritySafeCritical]
548  [ComVisible(false)]
549  [__DynamicallyInvokable]
550  public unsafe override string GetString(byte[] bytes, int index, int count)
551  {
552  if (bytes == null)
553  {
554  throw new ArgumentNullException("bytes", Environment.GetResourceString("ArgumentNull_Array"));
555  }
556  if (index < 0 || count < 0)
557  {
558  throw new ArgumentOutOfRangeException((index < 0) ? "index" : "count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
559  }
560  if (bytes.Length - index < count)
561  {
562  throw new ArgumentOutOfRangeException("bytes", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
563  }
564  if (bytes.Length == 0)
565  {
566  return string.Empty;
567  }
568  fixed (byte* ptr = bytes)
569  {
570  return string.CreateStringFromEncoding(ptr + index, count, this);
571  }
572  }
573 
574  [SecurityCritical]
575  internal unsafe override int GetByteCount(char* chars, int count, EncoderNLS encoder)
576  {
577  int num = count << 1;
578  if (num < 0)
579  {
580  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow"));
581  }
582  char* charStart = chars;
583  char* ptr = chars + count;
584  char c = '\0';
585  bool flag = false;
586  ulong* ptr2 = (ulong*)(ptr - 3);
587  EncoderFallbackBuffer encoderFallbackBuffer = null;
588  if (encoder != null)
589  {
590  c = encoder.charLeftOver;
591  if (c > '\0')
592  {
593  num += 2;
594  }
595  if (encoder.InternalHasFallbackBuffer)
596  {
597  encoderFallbackBuffer = encoder.FallbackBuffer;
598  if (encoderFallbackBuffer.Remaining > 0)
599  {
600  throw new ArgumentException(Environment.GetResourceString("Argument_EncoderFallbackNotEmpty", EncodingName, encoder.Fallback.GetType()));
601  }
602  encoderFallbackBuffer.InternalInitialize(charStart, ptr, encoder, setEncoder: false);
603  }
604  }
605  while (true)
606  {
607  char num2 = encoderFallbackBuffer?.InternalGetNextChar() ?? '\0';
608  char c2 = num2;
609  if (num2 != 0 || chars < ptr)
610  {
611  if (c2 == '\0')
612  {
613  if (!bigEndian && c == '\0' && ((long)chars & 7) == 0L)
614  {
615  ulong* ptr3;
616  for (ptr3 = (ulong*)chars; ptr3 < ptr2; ptr3++)
617  {
618  if ((-9223231297218904064L & (long)(*ptr3)) != 0L)
619  {
620  ulong num3 = (ulong)((-576188069258921984L & (long)(*ptr3)) ^ -2882066263381583872L);
621  if ((((long)num3 & -281474976710656L) == 0L || (num3 & 0xFFFF00000000) == 0L || (num3 & 4294901760u) == 0L || (num3 & 0xFFFF) == 0L) && ((-287953294993589248L & (long)(*ptr3)) ^ -2593835887162763264L) != 0L)
622  {
623  break;
624  }
625  }
626  }
627  chars = (char*)ptr3;
628  if (chars >= ptr)
629  {
630  goto IL_0278;
631  }
632  }
633  c2 = *chars;
634  chars++;
635  }
636  else
637  {
638  num += 2;
639  }
640  if (c2 >= '\ud800' && c2 <= '\udfff')
641  {
642  if (c2 <= '\udbff')
643  {
644  if (c > '\0')
645  {
646  chars--;
647  num -= 2;
648  if (encoderFallbackBuffer == null)
649  {
650  encoderFallbackBuffer = ((encoder != null) ? encoder.FallbackBuffer : encoderFallback.CreateFallbackBuffer());
651  encoderFallbackBuffer.InternalInitialize(charStart, ptr, encoder, setEncoder: false);
652  }
653  encoderFallbackBuffer.InternalFallback(c, ref chars);
654  c = '\0';
655  }
656  else
657  {
658  c = c2;
659  }
660  }
661  else if (c == '\0')
662  {
663  num -= 2;
664  if (encoderFallbackBuffer == null)
665  {
666  encoderFallbackBuffer = ((encoder != null) ? encoder.FallbackBuffer : encoderFallback.CreateFallbackBuffer());
667  encoderFallbackBuffer.InternalInitialize(charStart, ptr, encoder, setEncoder: false);
668  }
669  encoderFallbackBuffer.InternalFallback(c2, ref chars);
670  }
671  else
672  {
673  c = '\0';
674  }
675  }
676  else if (c > '\0')
677  {
678  chars--;
679  if (encoderFallbackBuffer == null)
680  {
681  encoderFallbackBuffer = ((encoder != null) ? encoder.FallbackBuffer : encoderFallback.CreateFallbackBuffer());
682  encoderFallbackBuffer.InternalInitialize(charStart, ptr, encoder, setEncoder: false);
683  }
684  encoderFallbackBuffer.InternalFallback(c, ref chars);
685  num -= 2;
686  c = '\0';
687  }
688  continue;
689  }
690  goto IL_0278;
691  IL_0278:
692  if (c <= '\0')
693  {
694  break;
695  }
696  num -= 2;
697  if (encoder != null && !encoder.MustFlush)
698  {
699  break;
700  }
701  if (flag)
702  {
703  throw new ArgumentException(Environment.GetResourceString("Argument_RecursiveFallback", c), "chars");
704  }
705  if (encoderFallbackBuffer == null)
706  {
707  encoderFallbackBuffer = ((encoder != null) ? encoder.FallbackBuffer : encoderFallback.CreateFallbackBuffer());
708  encoderFallbackBuffer.InternalInitialize(charStart, ptr, encoder, setEncoder: false);
709  }
710  encoderFallbackBuffer.InternalFallback(c, ref chars);
711  c = '\0';
712  flag = true;
713  }
714  return num;
715  }
716 
717  [SecurityCritical]
718  internal unsafe override int GetBytes(char* chars, int charCount, byte* bytes, int byteCount, EncoderNLS encoder)
719  {
720  char c = '\0';
721  bool flag = false;
722  byte* ptr = bytes + byteCount;
723  char* ptr2 = chars + charCount;
724  byte* ptr3 = bytes;
725  char* ptr4 = chars;
726  EncoderFallbackBuffer encoderFallbackBuffer = null;
727  if (encoder != null)
728  {
729  c = encoder.charLeftOver;
730  if (encoder.InternalHasFallbackBuffer)
731  {
732  encoderFallbackBuffer = encoder.FallbackBuffer;
733  if (encoderFallbackBuffer.Remaining > 0 && encoder.m_throwOnOverflow)
734  {
735  throw new ArgumentException(Environment.GetResourceString("Argument_EncoderFallbackNotEmpty", EncodingName, encoder.Fallback.GetType()));
736  }
737  encoderFallbackBuffer.InternalInitialize(ptr4, ptr2, encoder, setEncoder: false);
738  }
739  }
740  while (true)
741  {
742  char num = encoderFallbackBuffer?.InternalGetNextChar() ?? '\0';
743  char c2 = num;
744  if (num != 0 || chars < ptr2)
745  {
746  if (c2 == '\0')
747  {
748  if (!bigEndian && ((long)chars & 7) == 0L && ((long)bytes & 7) == 0L && c == '\0')
749  {
750  ulong* ptr5 = (ulong*)(chars - 3 + ((ptr - bytes >> 1 < ptr2 - chars) ? (ptr - bytes >> 1) : (ptr2 - chars)));
751  ulong* ptr6 = (ulong*)chars;
752  ulong* ptr7 = (ulong*)bytes;
753  while (ptr6 < ptr5)
754  {
755  if ((-9223231297218904064L & (long)(*ptr6)) != 0L)
756  {
757  ulong num2 = (ulong)((-576188069258921984L & (long)(*ptr6)) ^ -2882066263381583872L);
758  if ((((long)num2 & -281474976710656L) == 0L || (num2 & 0xFFFF00000000) == 0L || (num2 & 4294901760u) == 0L || (num2 & 0xFFFF) == 0L) && ((-287953294993589248L & (long)(*ptr6)) ^ -2593835887162763264L) != 0L)
759  {
760  break;
761  }
762  }
763  *ptr7 = *ptr6;
764  ptr6++;
765  ptr7++;
766  }
767  chars = (char*)ptr6;
768  bytes = (byte*)ptr7;
769  if (chars >= ptr2)
770  {
771  goto IL_0477;
772  }
773  }
774  else if (c == '\0' && !bigEndian && ((long)chars & 7) != ((long)bytes & 7) && ((int)bytes & 1) == 0)
775  {
776  long num3 = (ptr - bytes >> 1 < ptr2 - chars) ? (ptr - bytes >> 1) : (ptr2 - chars);
777  char* ptr8 = (char*)bytes;
778  char* ptr9 = chars + num3 - 1;
779  while (chars < ptr9)
780  {
781  if (*chars >= '\ud800' && *chars <= '\udfff')
782  {
783  if (*chars >= '\udc00' || chars[1] < '\udc00' || chars[1] > '\udfff')
784  {
785  break;
786  }
787  }
788  else if (chars[1] >= '\ud800' && chars[1] <= '\udfff')
789  {
790  *ptr8 = *chars;
791  ptr8++;
792  chars++;
793  continue;
794  }
795  *ptr8 = *chars;
796  ptr8[1] = chars[1];
797  ptr8 += 2;
798  chars += 2;
799  }
800  bytes = (byte*)ptr8;
801  if (chars >= ptr2)
802  {
803  goto IL_0477;
804  }
805  }
806  c2 = *chars;
807  chars++;
808  }
809  if (c2 >= '\ud800' && c2 <= '\udfff')
810  {
811  if (c2 <= '\udbff')
812  {
813  if (c > '\0')
814  {
815  chars--;
816  if (encoderFallbackBuffer == null)
817  {
818  encoderFallbackBuffer = ((encoder != null) ? encoder.FallbackBuffer : encoderFallback.CreateFallbackBuffer());
819  encoderFallbackBuffer.InternalInitialize(ptr4, ptr2, encoder, setEncoder: true);
820  }
821  encoderFallbackBuffer.InternalFallback(c, ref chars);
822  c = '\0';
823  }
824  else
825  {
826  c = c2;
827  }
828  continue;
829  }
830  if (c == '\0')
831  {
832  if (encoderFallbackBuffer == null)
833  {
834  encoderFallbackBuffer = ((encoder != null) ? encoder.FallbackBuffer : encoderFallback.CreateFallbackBuffer());
835  encoderFallbackBuffer.InternalInitialize(ptr4, ptr2, encoder, setEncoder: true);
836  }
837  encoderFallbackBuffer.InternalFallback(c2, ref chars);
838  continue;
839  }
840  if (bytes + 3 >= ptr)
841  {
842  if (encoderFallbackBuffer != null && encoderFallbackBuffer.bFallingBack)
843  {
844  encoderFallbackBuffer.MovePrevious();
845  encoderFallbackBuffer.MovePrevious();
846  }
847  else
848  {
849  chars -= 2;
850  }
851  ThrowBytesOverflow(encoder, bytes == ptr3);
852  c = '\0';
853  goto IL_0477;
854  }
855  if (bigEndian)
856  {
857  byte* intPtr = bytes;
858  bytes = intPtr + 1;
859  *intPtr = (byte)((int)c >> 8);
860  byte* intPtr2 = bytes;
861  bytes = intPtr2 + 1;
862  *intPtr2 = (byte)c;
863  }
864  else
865  {
866  byte* intPtr3 = bytes;
867  bytes = intPtr3 + 1;
868  *intPtr3 = (byte)c;
869  byte* intPtr4 = bytes;
870  bytes = intPtr4 + 1;
871  *intPtr4 = (byte)((int)c >> 8);
872  }
873  c = '\0';
874  }
875  else if (c > '\0')
876  {
877  chars--;
878  if (encoderFallbackBuffer == null)
879  {
880  encoderFallbackBuffer = ((encoder != null) ? encoder.FallbackBuffer : encoderFallback.CreateFallbackBuffer());
881  encoderFallbackBuffer.InternalInitialize(ptr4, ptr2, encoder, setEncoder: true);
882  }
883  encoderFallbackBuffer.InternalFallback(c, ref chars);
884  c = '\0';
885  continue;
886  }
887  if (bytes + 1 < ptr)
888  {
889  if (bigEndian)
890  {
891  byte* intPtr5 = bytes;
892  bytes = intPtr5 + 1;
893  *intPtr5 = (byte)((int)c2 >> 8);
894  byte* intPtr6 = bytes;
895  bytes = intPtr6 + 1;
896  *intPtr6 = (byte)c2;
897  }
898  else
899  {
900  byte* intPtr7 = bytes;
901  bytes = intPtr7 + 1;
902  *intPtr7 = (byte)c2;
903  byte* intPtr8 = bytes;
904  bytes = intPtr8 + 1;
905  *intPtr8 = (byte)((int)c2 >> 8);
906  }
907  continue;
908  }
909  if (encoderFallbackBuffer != null && encoderFallbackBuffer.bFallingBack)
910  {
911  encoderFallbackBuffer.MovePrevious();
912  }
913  else
914  {
915  chars--;
916  }
917  ThrowBytesOverflow(encoder, bytes == ptr3);
918  }
919  goto IL_0477;
920  IL_0477:
921  if (c <= '\0' || (encoder != null && !encoder.MustFlush))
922  {
923  break;
924  }
925  if (flag)
926  {
927  throw new ArgumentException(Environment.GetResourceString("Argument_RecursiveFallback", c), "chars");
928  }
929  if (encoderFallbackBuffer == null)
930  {
931  encoderFallbackBuffer = ((encoder != null) ? encoder.FallbackBuffer : encoderFallback.CreateFallbackBuffer());
932  encoderFallbackBuffer.InternalInitialize(ptr4, ptr2, encoder, setEncoder: true);
933  }
934  encoderFallbackBuffer.InternalFallback(c, ref chars);
935  c = '\0';
936  flag = true;
937  }
938  if (encoder != null)
939  {
940  encoder.charLeftOver = c;
941  encoder.m_charsUsed = (int)(chars - ptr4);
942  }
943  return (int)(bytes - ptr3);
944  }
945 
946  [SecurityCritical]
947  internal unsafe override int GetCharCount(byte* bytes, int count, DecoderNLS baseDecoder)
948  {
949  Decoder decoder = (Decoder)baseDecoder;
950  byte* ptr = bytes + count;
951  byte* byteStart = bytes;
952  int num = -1;
953  char c = '\0';
954  int num2 = count >> 1;
955  ulong* ptr2 = (ulong*)(ptr - 7);
956  DecoderFallbackBuffer decoderFallbackBuffer = null;
957  if (decoder != null)
958  {
959  num = decoder.lastByte;
960  c = decoder.lastChar;
961  if (c > '\0')
962  {
963  num2++;
964  }
965  if (num >= 0 && (count & 1) == 1)
966  {
967  num2++;
968  }
969  }
970  while (bytes < ptr)
971  {
972  if (!bigEndian && ((long)bytes & 7) == 0L && num == -1 && c == '\0')
973  {
974  ulong* ptr3;
975  for (ptr3 = (ulong*)bytes; ptr3 < ptr2; ptr3++)
976  {
977  if ((-9223231297218904064L & (long)(*ptr3)) != 0L)
978  {
979  ulong num3 = (ulong)((-576188069258921984L & (long)(*ptr3)) ^ -2882066263381583872L);
980  if ((((long)num3 & -281474976710656L) == 0L || (num3 & 0xFFFF00000000) == 0L || (num3 & 4294901760u) == 0L || (num3 & 0xFFFF) == 0L) && ((-287953294993589248L & (long)(*ptr3)) ^ -2593835887162763264L) != 0L)
981  {
982  break;
983  }
984  }
985  }
986  bytes = (byte*)ptr3;
987  if (bytes >= ptr)
988  {
989  break;
990  }
991  }
992  if (num < 0)
993  {
994  byte* intPtr = bytes;
995  bytes = intPtr + 1;
996  num = *intPtr;
997  if (bytes >= ptr)
998  {
999  break;
1000  }
1001  }
1002  char c2;
1003  if (bigEndian)
1004  {
1005  int num4 = num << 8;
1006  byte* intPtr2 = bytes;
1007  bytes = intPtr2 + 1;
1008  c2 = (char)(num4 | *intPtr2);
1009  }
1010  else
1011  {
1012  byte* intPtr3 = bytes;
1013  bytes = intPtr3 + 1;
1014  c2 = (char)((*intPtr3 << 8) | num);
1015  }
1016  num = -1;
1017  if (c2 >= '\ud800' && c2 <= '\udfff')
1018  {
1019  if (c2 <= '\udbff')
1020  {
1021  if (c > '\0')
1022  {
1023  num2--;
1024  byte[] array = null;
1025  array = ((!bigEndian) ? new byte[2]
1026  {
1027  (byte)c,
1028  (byte)((int)c >> 8)
1029  } : new byte[2]
1030  {
1031  (byte)((int)c >> 8),
1032  (byte)c
1033  });
1034  if (decoderFallbackBuffer == null)
1035  {
1036  decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
1037  decoderFallbackBuffer.InternalInitialize(byteStart, null);
1038  }
1039  num2 += decoderFallbackBuffer.InternalFallback(array, bytes);
1040  }
1041  c = c2;
1042  }
1043  else if (c == '\0')
1044  {
1045  num2--;
1046  byte[] array2 = null;
1047  array2 = ((!bigEndian) ? new byte[2]
1048  {
1049  (byte)c2,
1050  (byte)((int)c2 >> 8)
1051  } : new byte[2]
1052  {
1053  (byte)((int)c2 >> 8),
1054  (byte)c2
1055  });
1056  if (decoderFallbackBuffer == null)
1057  {
1058  decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
1059  decoderFallbackBuffer.InternalInitialize(byteStart, null);
1060  }
1061  num2 += decoderFallbackBuffer.InternalFallback(array2, bytes);
1062  }
1063  else
1064  {
1065  c = '\0';
1066  }
1067  }
1068  else if (c > '\0')
1069  {
1070  num2--;
1071  byte[] array3 = null;
1072  array3 = ((!bigEndian) ? new byte[2]
1073  {
1074  (byte)c,
1075  (byte)((int)c >> 8)
1076  } : new byte[2]
1077  {
1078  (byte)((int)c >> 8),
1079  (byte)c
1080  });
1081  if (decoderFallbackBuffer == null)
1082  {
1083  decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
1084  decoderFallbackBuffer.InternalInitialize(byteStart, null);
1085  }
1086  num2 += decoderFallbackBuffer.InternalFallback(array3, bytes);
1087  c = '\0';
1088  }
1089  }
1090  if (decoder == null || decoder.MustFlush)
1091  {
1092  if (c > '\0')
1093  {
1094  num2--;
1095  byte[] array4 = null;
1096  array4 = ((!bigEndian) ? new byte[2]
1097  {
1098  (byte)c,
1099  (byte)((int)c >> 8)
1100  } : new byte[2]
1101  {
1102  (byte)((int)c >> 8),
1103  (byte)c
1104  });
1105  if (decoderFallbackBuffer == null)
1106  {
1107  decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
1108  decoderFallbackBuffer.InternalInitialize(byteStart, null);
1109  }
1110  num2 += decoderFallbackBuffer.InternalFallback(array4, bytes);
1111  c = '\0';
1112  }
1113  if (num >= 0)
1114  {
1115  if (decoderFallbackBuffer == null)
1116  {
1117  decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
1118  decoderFallbackBuffer.InternalInitialize(byteStart, null);
1119  }
1120  num2 += decoderFallbackBuffer.InternalFallback(new byte[1]
1121  {
1122  (byte)num
1123  }, bytes);
1124  num = -1;
1125  }
1126  }
1127  if (c > '\0')
1128  {
1129  num2--;
1130  }
1131  return num2;
1132  }
1133 
1134  [SecurityCritical]
1135  internal unsafe override int GetChars(byte* bytes, int byteCount, char* chars, int charCount, DecoderNLS baseDecoder)
1136  {
1137  Decoder decoder = (Decoder)baseDecoder;
1138  int num = -1;
1139  char c = '\0';
1140  if (decoder != null)
1141  {
1142  num = decoder.lastByte;
1143  c = decoder.lastChar;
1144  }
1145  DecoderFallbackBuffer decoderFallbackBuffer = null;
1146  byte* ptr = bytes + byteCount;
1147  char* ptr2 = chars + charCount;
1148  byte* ptr3 = bytes;
1149  char* ptr4 = chars;
1150  while (bytes < ptr)
1151  {
1152  if (!bigEndian && ((long)chars & 7) == 0L && ((long)bytes & 7) == 0L && num == -1 && c == '\0')
1153  {
1154  ulong* ptr5 = (ulong*)(bytes - 7 + ((ptr - bytes >> 1 < ptr2 - chars) ? (ptr - bytes) : (ptr2 - chars << 1)));
1155  ulong* ptr6 = (ulong*)bytes;
1156  ulong* ptr7 = (ulong*)chars;
1157  while (ptr6 < ptr5)
1158  {
1159  if ((-9223231297218904064L & (long)(*ptr6)) != 0L)
1160  {
1161  ulong num2 = (ulong)((-576188069258921984L & (long)(*ptr6)) ^ -2882066263381583872L);
1162  if ((((long)num2 & -281474976710656L) == 0L || (num2 & 0xFFFF00000000) == 0L || (num2 & 4294901760u) == 0L || (num2 & 0xFFFF) == 0L) && ((-287953294993589248L & (long)(*ptr6)) ^ -2593835887162763264L) != 0L)
1163  {
1164  break;
1165  }
1166  }
1167  *ptr7 = *ptr6;
1168  ptr6++;
1169  ptr7++;
1170  }
1171  chars = (char*)ptr7;
1172  bytes = (byte*)ptr6;
1173  if (bytes >= ptr)
1174  {
1175  break;
1176  }
1177  }
1178  if (num < 0)
1179  {
1180  byte* intPtr = bytes;
1181  bytes = intPtr + 1;
1182  num = *intPtr;
1183  continue;
1184  }
1185  char c2;
1186  if (bigEndian)
1187  {
1188  int num3 = num << 8;
1189  byte* intPtr2 = bytes;
1190  bytes = intPtr2 + 1;
1191  c2 = (char)(num3 | *intPtr2);
1192  }
1193  else
1194  {
1195  byte* intPtr3 = bytes;
1196  bytes = intPtr3 + 1;
1197  c2 = (char)((*intPtr3 << 8) | num);
1198  }
1199  num = -1;
1200  if (c2 >= '\ud800' && c2 <= '\udfff')
1201  {
1202  if (c2 <= '\udbff')
1203  {
1204  if (c > '\0')
1205  {
1206  byte[] array = null;
1207  array = ((!bigEndian) ? new byte[2]
1208  {
1209  (byte)c,
1210  (byte)((int)c >> 8)
1211  } : new byte[2]
1212  {
1213  (byte)((int)c >> 8),
1214  (byte)c
1215  });
1216  if (decoderFallbackBuffer == null)
1217  {
1218  decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
1219  decoderFallbackBuffer.InternalInitialize(ptr3, ptr2);
1220  }
1221  if (!decoderFallbackBuffer.InternalFallback(array, bytes, ref chars))
1222  {
1223  bytes -= 2;
1224  decoderFallbackBuffer.InternalReset();
1225  ThrowCharsOverflow(decoder, chars == ptr4);
1226  break;
1227  }
1228  }
1229  c = c2;
1230  continue;
1231  }
1232  if (c == '\0')
1233  {
1234  byte[] array2 = null;
1235  array2 = ((!bigEndian) ? new byte[2]
1236  {
1237  (byte)c2,
1238  (byte)((int)c2 >> 8)
1239  } : new byte[2]
1240  {
1241  (byte)((int)c2 >> 8),
1242  (byte)c2
1243  });
1244  if (decoderFallbackBuffer == null)
1245  {
1246  decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
1247  decoderFallbackBuffer.InternalInitialize(ptr3, ptr2);
1248  }
1249  if (!decoderFallbackBuffer.InternalFallback(array2, bytes, ref chars))
1250  {
1251  bytes -= 2;
1252  decoderFallbackBuffer.InternalReset();
1253  ThrowCharsOverflow(decoder, chars == ptr4);
1254  break;
1255  }
1256  continue;
1257  }
1258  if (chars >= ptr2 - 1)
1259  {
1260  bytes -= 2;
1261  ThrowCharsOverflow(decoder, chars == ptr4);
1262  break;
1263  }
1264  char* intPtr4 = chars;
1265  chars = intPtr4 + 1;
1266  *intPtr4 = c;
1267  c = '\0';
1268  }
1269  else if (c > '\0')
1270  {
1271  byte[] array3 = null;
1272  array3 = ((!bigEndian) ? new byte[2]
1273  {
1274  (byte)c,
1275  (byte)((int)c >> 8)
1276  } : new byte[2]
1277  {
1278  (byte)((int)c >> 8),
1279  (byte)c
1280  });
1281  if (decoderFallbackBuffer == null)
1282  {
1283  decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
1284  decoderFallbackBuffer.InternalInitialize(ptr3, ptr2);
1285  }
1286  if (!decoderFallbackBuffer.InternalFallback(array3, bytes, ref chars))
1287  {
1288  bytes -= 2;
1289  decoderFallbackBuffer.InternalReset();
1290  ThrowCharsOverflow(decoder, chars == ptr4);
1291  break;
1292  }
1293  c = '\0';
1294  }
1295  if (chars >= ptr2)
1296  {
1297  bytes -= 2;
1298  ThrowCharsOverflow(decoder, chars == ptr4);
1299  break;
1300  }
1301  char* intPtr5 = chars;
1302  chars = intPtr5 + 1;
1303  *intPtr5 = c2;
1304  }
1305  if (decoder == null || decoder.MustFlush)
1306  {
1307  if (c > '\0')
1308  {
1309  byte[] array4 = null;
1310  array4 = ((!bigEndian) ? new byte[2]
1311  {
1312  (byte)c,
1313  (byte)((int)c >> 8)
1314  } : new byte[2]
1315  {
1316  (byte)((int)c >> 8),
1317  (byte)c
1318  });
1319  if (decoderFallbackBuffer == null)
1320  {
1321  decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
1322  decoderFallbackBuffer.InternalInitialize(ptr3, ptr2);
1323  }
1324  if (!decoderFallbackBuffer.InternalFallback(array4, bytes, ref chars))
1325  {
1326  bytes -= 2;
1327  if (num >= 0)
1328  {
1329  bytes--;
1330  }
1331  decoderFallbackBuffer.InternalReset();
1332  ThrowCharsOverflow(decoder, chars == ptr4);
1333  bytes += 2;
1334  if (num >= 0)
1335  {
1336  bytes++;
1337  }
1338  goto IL_04a2;
1339  }
1340  c = '\0';
1341  }
1342  if (num >= 0)
1343  {
1344  if (decoderFallbackBuffer == null)
1345  {
1346  decoderFallbackBuffer = ((decoder != null) ? decoder.FallbackBuffer : decoderFallback.CreateFallbackBuffer());
1347  decoderFallbackBuffer.InternalInitialize(ptr3, ptr2);
1348  }
1349  if (!decoderFallbackBuffer.InternalFallback(new byte[1]
1350  {
1351  (byte)num
1352  }, bytes, ref chars))
1353  {
1354  bytes--;
1355  decoderFallbackBuffer.InternalReset();
1356  ThrowCharsOverflow(decoder, chars == ptr4);
1357  bytes++;
1358  }
1359  else
1360  {
1361  num = -1;
1362  }
1363  }
1364  }
1365  goto IL_04a2;
1366  IL_04a2:
1367  if (decoder != null)
1368  {
1369  decoder.m_bytesUsed = (int)(bytes - ptr3);
1370  decoder.lastChar = c;
1371  decoder.lastByte = num;
1372  }
1373  return (int)(chars - ptr4);
1374  }
1375 
1378  [ComVisible(false)]
1379  [__DynamicallyInvokable]
1380  public override Encoder GetEncoder()
1381  {
1382  return new EncoderNLS(this);
1383  }
1384 
1387  [__DynamicallyInvokable]
1388  public override System.Text.Decoder GetDecoder()
1389  {
1390  return new Decoder(this);
1391  }
1392 
1395  [__DynamicallyInvokable]
1396  public override byte[] GetPreamble()
1397  {
1398  if (byteOrderMark)
1399  {
1400  if (!bigEndian)
1401  {
1402  return new byte[2]
1403  {
1404  255,
1405  254
1406  };
1407  }
1408  return new byte[2]
1409  {
1410  254,
1411  255
1412  };
1413  }
1414  return EmptyArray<byte>.Value;
1415  }
1416 
1424  [__DynamicallyInvokable]
1425  public override int GetMaxByteCount(int charCount)
1426  {
1427  if (charCount < 0)
1428  {
1429  throw new ArgumentOutOfRangeException("charCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
1430  }
1431  long num = (long)charCount + 1L;
1432  if (base.EncoderFallback.MaxCharCount > 1)
1433  {
1434  num *= base.EncoderFallback.MaxCharCount;
1435  }
1436  num <<= 1;
1437  if (num > int.MaxValue)
1438  {
1439  throw new ArgumentOutOfRangeException("charCount", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow"));
1440  }
1441  return (int)num;
1442  }
1443 
1451  [__DynamicallyInvokable]
1452  public override int GetMaxCharCount(int byteCount)
1453  {
1454  if (byteCount < 0)
1455  {
1456  throw new ArgumentOutOfRangeException("byteCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
1457  }
1458  long num = (long)(byteCount >> 1) + (long)(byteCount & 1) + 1;
1459  if (base.DecoderFallback.MaxCharCount > 1)
1460  {
1461  num *= base.DecoderFallback.MaxCharCount;
1462  }
1463  if (num > int.MaxValue)
1464  {
1465  throw new ArgumentOutOfRangeException("byteCount", Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow"));
1466  }
1467  return (int)num;
1468  }
1469 
1474  [__DynamicallyInvokable]
1475  public override bool Equals(object value)
1476  {
1477  UnicodeEncoding unicodeEncoding = value as UnicodeEncoding;
1478  if (unicodeEncoding != null)
1479  {
1480  if (CodePage == unicodeEncoding.CodePage && byteOrderMark == unicodeEncoding.byteOrderMark && bigEndian == unicodeEncoding.bigEndian && base.EncoderFallback.Equals(unicodeEncoding.EncoderFallback))
1481  {
1482  return base.DecoderFallback.Equals(unicodeEncoding.DecoderFallback);
1483  }
1484  return false;
1485  }
1486  return false;
1487  }
1488 
1491  [__DynamicallyInvokable]
1492  public override int GetHashCode()
1493  {
1494  return CodePage + base.EncoderFallback.GetHashCode() + base.DecoderFallback.GetHashCode() + (byteOrderMark ? 4 : 0) + (bigEndian ? 8 : 0);
1495  }
1496  }
1497 }
Represents a character encoding.To browse the .NET Framework source code for this type,...
Definition: Encoding.cs:15
unsafe override int GetBytes(string s, int charIndex, int charCount, byte[] bytes, int byteIndex)
Encodes a set of characters from the specified T:System.String into the specified byte array.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
override int GetMaxCharCount(int byteCount)
Calculates the maximum number of characters produced by decoding the specified number of bytes.
Converts a set of characters into a sequence of bytes.
Definition: Encoder.cs:11
unsafe override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
Encodes a set of characters from the specified character array into the specified byte array.
override byte [] GetPreamble()
Returns a Unicode byte order mark encoded in UTF-16 format, if the constructor for this instance requ...
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
DecoderFallback DecoderFallback
Gets or sets the T:System.Text.DecoderFallback object for the current T:System.Text....
Definition: Encoding.cs:884
static DecoderFallback ExceptionFallback
Gets an object that throws an exception when an input byte sequence cannot be decoded.
EncoderFallback EncoderFallback
Gets or sets the T:System.Text.EncoderFallback object for the current T:System.Text....
Definition: Encoding.cs:857
Describes the source and destination of a given serialized stream, and provides an additional caller-...
override System.Text.Decoder GetDecoder()
Obtains a decoder that converts a UTF-16 encoded sequence of bytes into a sequence of Unicode charact...
override bool Equals(object value)
Determines whether the specified T:System.Object is equal to the current T:System....
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
UnicodeEncoding(bool bigEndian, bool byteOrderMark)
Initializes a new instance of the T:System.Text.UnicodeEncoding class. Parameters specify whether to ...
Represents a UTF-16 encoding of Unicode characters.
override int GetHashCode()
Returns the hash code for the current instance.
virtual int CodePage
When overridden in a derived class, gets the code page identifier of the current T:System....
Definition: Encoding.cs:948
Converts a sequence of encoded bytes into a set of characters.
Definition: Decoder.cs:11
virtual string EncodingName
When overridden in a derived class, gets the human-readable description of the current encoding.
Definition: Encoding.cs:724
unsafe override int GetByteCount(char[] chars, int index, int count)
Calculates the number of bytes produced by encoding a set of characters from the specified character ...
Provides a failure-handling mechanism, called a fallback, for an encoded input byte sequence that can...
The exception thrown when an error occurs during serialization or deserialization.
UnicodeEncoding()
Initializes a new instance of the T:System.Text.UnicodeEncoding class.
unsafe override int GetBytes(char *chars, int charCount, byte *bytes, int byteCount)
Encodes a set of characters starting at the specified character pointer into a sequence of bytes that...
const int CharSize
Represents the Unicode character size in bytes. This field is a constant.
unsafe override int GetCharCount(byte[] bytes, int index, int count)
Calculates the number of characters produced by decoding a sequence of bytes from the specified byte ...
unsafe override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
Decodes a sequence of bytes from the specified byte array into the specified character array.
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
unsafe override int GetChars(byte *bytes, int byteCount, char *chars, int charCount)
Decodes a sequence of bytes starting at the specified byte pointer into a set of characters that are ...
Allows an object to control its own serialization and deserialization.
Definition: ISerializable.cs:8
unsafe override int GetByteCount(string s)
Calculates the number of bytes produced by encoding the characters in the specified string.
Specifies that the class can be serialized.
override Encoder GetEncoder()
Obtains an encoder that converts a sequence of Unicode characters into a UTF-16 encoded sequence of b...
unsafe override int GetCharCount(byte *bytes, int count)
Calculates the number of characters produced by decoding a sequence of bytes starting at the specifie...
Encoding()
Initializes a new instance of the T:System.Text.Encoding class.
Definition: Encoding.cs:1053
static EncoderFallback ExceptionFallback
Gets an object that throws an exception when an input character cannot be encoded.
void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data needed to serialize the ta...
unsafe override string GetString(byte[] bytes, int index, int count)
Decodes a range of bytes from a byte array into a string.
override int GetMaxByteCount(int charCount)
Calculates the maximum number of bytes produced by encoding the specified number of characters.
unsafe override int GetByteCount(char *chars, int count)
Calculates the number of bytes produced by encoding a set of characters starting at the specified cha...