mscorlib(4.0.0.0) API with additions
Decoder.cs
3 using System.Security;
4 
5 namespace System.Text
6 {
9  [ComVisible(true)]
10  [__DynamicallyInvokable]
11  public abstract class Decoder
12  {
13  internal DecoderFallback m_fallback;
14 
15  [NonSerialized]
16  internal DecoderFallbackBuffer m_fallbackBuffer;
17 
22  [ComVisible(false)]
23  [__DynamicallyInvokable]
25  {
26  [__DynamicallyInvokable]
27  get
28  {
29  return m_fallback;
30  }
31  [__DynamicallyInvokable]
32  set
33  {
34  if (value == null)
35  {
36  throw new ArgumentNullException("value");
37  }
38  if (m_fallbackBuffer != null && m_fallbackBuffer.Remaining > 0)
39  {
40  throw new ArgumentException(Environment.GetResourceString("Argument_FallbackBufferNotEmpty"), "value");
41  }
42  m_fallback = value;
43  m_fallbackBuffer = null;
44  }
45  }
46 
49  [ComVisible(false)]
50  [__DynamicallyInvokable]
52  {
53  [__DynamicallyInvokable]
54  get
55  {
56  if (m_fallbackBuffer == null)
57  {
58  if (m_fallback != null)
59  {
60  m_fallbackBuffer = m_fallback.CreateFallbackBuffer();
61  }
62  else
63  {
65  }
66  }
67  return m_fallbackBuffer;
68  }
69  }
70 
71  internal bool InternalHasFallbackBuffer => m_fallbackBuffer != null;
72 
73  internal void SerializeDecoder(SerializationInfo info)
74  {
75  info.AddValue("m_fallback", m_fallback);
76  }
77 
79  [__DynamicallyInvokable]
80  protected Decoder()
81  {
82  }
83 
85  [ComVisible(false)]
86  [__DynamicallyInvokable]
87  public virtual void Reset()
88  {
89  byte[] bytes = new byte[0];
90  char[] chars = new char[GetCharCount(bytes, 0, 0, flush: true)];
91  GetChars(bytes, 0, 0, chars, 0, flush: true);
92  if (m_fallbackBuffer != null)
93  {
94  m_fallbackBuffer.Reset();
95  }
96  }
97 
110  [__DynamicallyInvokable]
111  public abstract int GetCharCount(byte[] bytes, int index, int count);
112 
127  [ComVisible(false)]
128  [__DynamicallyInvokable]
129  public virtual int GetCharCount(byte[] bytes, int index, int count, bool flush)
130  {
131  return GetCharCount(bytes, index, count);
132  }
133 
146  [SecurityCritical]
147  [CLSCompliant(false)]
148  [ComVisible(false)]
149  public unsafe virtual int GetCharCount(byte* bytes, int count, bool flush)
150  {
151  if (bytes == null)
152  {
153  throw new ArgumentNullException("bytes", Environment.GetResourceString("ArgumentNull_Array"));
154  }
155  if (count < 0)
156  {
157  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
158  }
159  byte[] array = new byte[count];
160  for (int i = 0; i < count; i++)
161  {
162  array[i] = bytes[i];
163  }
164  return GetCharCount(array, 0, count);
165  }
166 
185  [__DynamicallyInvokable]
186  public abstract int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex);
187 
208  [__DynamicallyInvokable]
209  public virtual int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, bool flush)
210  {
211  return GetChars(bytes, byteIndex, byteCount, chars, charIndex);
212  }
213 
231  [SecurityCritical]
232  [CLSCompliant(false)]
233  [ComVisible(false)]
234  public unsafe virtual int GetChars(byte* bytes, int byteCount, char* chars, int charCount, bool flush)
235  {
236  if (chars == null || bytes == null)
237  {
238  throw new ArgumentNullException((chars == null) ? "chars" : "bytes", Environment.GetResourceString("ArgumentNull_Array"));
239  }
240  if (byteCount < 0 || charCount < 0)
241  {
242  throw new ArgumentOutOfRangeException((byteCount < 0) ? "byteCount" : "charCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
243  }
244  byte[] array = new byte[byteCount];
245  for (int i = 0; i < byteCount; i++)
246  {
247  array[i] = bytes[i];
248  }
249  char[] array2 = new char[charCount];
250  int chars2 = GetChars(array, 0, byteCount, array2, 0, flush);
251  if (chars2 < charCount)
252  {
253  charCount = chars2;
254  }
255  for (int i = 0; i < charCount; i++)
256  {
257  chars[i] = array2[i];
258  }
259  return charCount;
260  }
261 
281  [ComVisible(false)]
282  [__DynamicallyInvokable]
283  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)
284  {
285  if (bytes == null || chars == null)
286  {
287  throw new ArgumentNullException((bytes == null) ? "bytes" : "chars", Environment.GetResourceString("ArgumentNull_Array"));
288  }
289  if (byteIndex < 0 || byteCount < 0)
290  {
291  throw new ArgumentOutOfRangeException((byteIndex < 0) ? "byteIndex" : "byteCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
292  }
293  if (charIndex < 0 || charCount < 0)
294  {
295  throw new ArgumentOutOfRangeException((charIndex < 0) ? "charIndex" : "charCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
296  }
297  if (bytes.Length - byteIndex < byteCount)
298  {
299  throw new ArgumentOutOfRangeException("bytes", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
300  }
301  if (chars.Length - charIndex < charCount)
302  {
303  throw new ArgumentOutOfRangeException("chars", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
304  }
305  for (bytesUsed = byteCount; bytesUsed > 0; bytesUsed /= 2)
306  {
307  if (GetCharCount(bytes, byteIndex, bytesUsed, flush) <= charCount)
308  {
309  charsUsed = GetChars(bytes, byteIndex, bytesUsed, chars, charIndex, flush);
310  completed = (bytesUsed == byteCount && (m_fallbackBuffer == null || m_fallbackBuffer.Remaining == 0));
311  return;
312  }
313  flush = false;
314  }
315  throw new ArgumentException(Environment.GetResourceString("Argument_ConversionOverflow"));
316  }
317 
335  [SecurityCritical]
336  [CLSCompliant(false)]
337  [ComVisible(false)]
338  public unsafe virtual void Convert(byte* bytes, int byteCount, char* chars, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed)
339  {
340  if (chars == null || bytes == null)
341  {
342  throw new ArgumentNullException((chars == null) ? "chars" : "bytes", Environment.GetResourceString("ArgumentNull_Array"));
343  }
344  if (byteCount < 0 || charCount < 0)
345  {
346  throw new ArgumentOutOfRangeException((byteCount < 0) ? "byteCount" : "charCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
347  }
348  for (bytesUsed = byteCount; bytesUsed > 0; bytesUsed /= 2)
349  {
350  if (GetCharCount(bytes, bytesUsed, flush) <= charCount)
351  {
352  charsUsed = GetChars(bytes, bytesUsed, chars, charCount, flush);
353  completed = (bytesUsed == byteCount && (m_fallbackBuffer == null || m_fallbackBuffer.Remaining == 0));
354  return;
355  }
356  flush = false;
357  }
358  throw new ArgumentException(Environment.GetResourceString("Argument_ConversionOverflow"));
359  }
360  }
361 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
virtual int GetCharCount(byte[] bytes, int index, int count, bool flush)
When overridden in a derived class, calculates the number of characters produced by decoding a sequen...
Definition: Decoder.cs:129
DecoderFallback Fallback
Gets or sets a T:System.Text.DecoderFallback object for the current T:System.Text....
Definition: Decoder.cs:25
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
static DecoderFallback ReplacementFallback
Gets an object that outputs a substitute string in place of an input byte sequence that cannot be dec...
virtual void Reset()
Initializes all data and state information pertaining to this fallback buffer.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
Decoder()
Initializes a new instance of the T:System.Text.Decoder class.
Definition: Decoder.cs:80
abstract int GetCharCount(byte[] bytes, int index, int count)
When overridden in a derived class, calculates the number of characters produced by decoding a sequen...
Provides a buffer that allows a fallback handler to return an alternate string to a decoder when it c...
virtual unsafe void Convert(byte *bytes, int byteCount, char *chars, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed)
Converts a buffer of encoded bytes to UTF-16 encoded characters and stores the result in another buff...
Definition: Decoder.cs:338
virtual unsafe int GetChars(byte *bytes, int byteCount, char *chars, int charCount, bool flush)
When overridden in a derived class, decodes a sequence of bytes starting at the specified byte pointe...
Definition: Decoder.cs:234
Converts a sequence of encoded bytes into a set of characters.
Definition: Decoder.cs:11
abstract int Remaining
When overridden in a derived class, gets the number of characters in the current T:System....
Provides a failure-handling mechanism, called a fallback, for an encoded input byte sequence that can...
virtual void Reset()
When overridden in a derived class, sets the decoder back to its initial state.
Definition: Decoder.cs:87
abstract DecoderFallbackBuffer CreateFallbackBuffer()
When overridden in a derived class, initializes a new instance of the T:System.Text....
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
The exception that is thrown when one of the arguments provided to a method is not valid.
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)
Converts an array of encoded bytes to UTF-16 encoded characters and stores the result in a character ...
Definition: Decoder.cs:283
DecoderFallbackBuffer FallbackBuffer
Gets the T:System.Text.DecoderFallbackBuffer object associated with the current T:System....
Definition: Decoder.cs:52
abstract int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
When overridden in a derived class, decodes a sequence of bytes from the specified byte array and any...
Specifies that the class can be serialized.
virtual unsafe int GetCharCount(byte *bytes, int count, bool flush)
When overridden in a derived class, calculates the number of characters produced by decoding a sequen...
Definition: Decoder.cs:149
virtual int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, bool flush)
When overridden in a derived class, decodes a sequence of bytes from the specified byte array and any...
Definition: Decoder.cs:209