private const int CodePageUTF32 = 12000;
private const int CodePageUTF32BE = 12001;
- internal int m_codePage = 0;
+ internal int _codePage = 0;
- // dataItem should be internal (not private). otherwise it will break during the deserialization
- // of the data came from Everett
- internal CodePageDataItem dataItem = null;
-
- [NonSerialized]
- internal bool m_deserializedFromEverett = false;
+ internal CodePageDataItem _dataItem = null;
// Because of encoders we may be read only
[OptionalField(VersionAdded = 2)]
- private bool m_isReadOnly = true;
+ private bool _isReadOnly = true;
// Encoding (encoder) fallback
- [OptionalField(VersionAdded = 2)]
internal EncoderFallback encoderFallback = null;
- [OptionalField(VersionAdded = 2)]
internal DecoderFallback decoderFallback = null;
protected Encoding() : this(0)
Contract.EndContractBlock();
// Remember code page
- m_codePage = codePage;
+ _codePage = codePage;
// Use default encoder/decoder fallbacks
this.SetDefaultFallbacks();
Contract.EndContractBlock();
// Remember code page
- m_codePage = codePage;
+ _codePage = codePage;
this.encoderFallback = encoderFallback ?? new InternalEncoderBestFitFallback(this);
this.decoderFallback = decoderFallback ?? new InternalDecoderBestFitFallback(this);
{
// For UTF-X encodings, we use a replacement fallback with an "\xFFFD" string,
// For ASCII we use "?" replacement fallback, etc.
- this.encoderFallback = new InternalEncoderBestFitFallback(this);
- this.decoderFallback = new InternalDecoderBestFitFallback(this);
- }
-
-
- #region Serialization
- internal void OnDeserializing()
- {
- // intialize the optional Whidbey fields
- encoderFallback = null;
- decoderFallback = null;
- m_isReadOnly = true;
- }
-
- internal void OnDeserialized()
- {
- if (encoderFallback == null || decoderFallback == null)
- {
- m_deserializedFromEverett = true;
- SetDefaultFallbacks();
- }
-
- // dataItem is always recalculated from the code page #
- dataItem = null;
- }
-
- [OnDeserializing]
- private void OnDeserializing(StreamingContext ctx)
- {
- OnDeserializing();
- }
-
-
- [OnDeserialized]
- private void OnDeserialized(StreamingContext ctx)
- {
- OnDeserialized();
- }
-
- [OnSerializing]
- private void OnSerializing(StreamingContext ctx)
- {
- // to be consistent with SerializeEncoding
- dataItem = null;
- }
-
- // the following two methods are used for the inherited classes which implemented ISerializable
- // Deserialization Helper
- internal void DeserializeEncoding(SerializationInfo info, StreamingContext context)
- {
- // Any info?
- if (info == null) throw new ArgumentNullException(nameof(info));
- Contract.EndContractBlock();
-
- // All versions have a code page
- this.m_codePage = (int)info.GetValue("m_codePage", typeof(int));
-
- // We can get dataItem on the fly if needed, and the index is different between versions
- // so ignore whatever dataItem data we get from Everett.
- this.dataItem = null;
-
- // See if we have a code page
- try
- {
- //
- // Try Whidbey V2.0 Fields
- //
-
- m_isReadOnly = (bool)info.GetValue("m_isReadOnly", typeof(bool));
-
- this.encoderFallback = (EncoderFallback)info.GetValue("encoderFallback", typeof(EncoderFallback));
- this.decoderFallback = (DecoderFallback)info.GetValue("decoderFallback", typeof(DecoderFallback));
- }
- catch (SerializationException)
- {
- //
- // Didn't have Whidbey things, must be Everett
- //
- this.m_deserializedFromEverett = true;
-
- // May as well be read only
- m_isReadOnly = true;
- SetDefaultFallbacks();
- }
+ encoderFallback = new InternalEncoderBestFitFallback(this);
+ decoderFallback = new InternalDecoderBestFitFallback(this);
}
- // Serialization Helper
- internal void SerializeEncoding(SerializationInfo info, StreamingContext context)
- {
- // Any Info?
- if (info == null) throw new ArgumentNullException(nameof(info));
- Contract.EndContractBlock();
-
- // These are new V2.0 Whidbey stuff
- info.AddValue("m_isReadOnly", m_isReadOnly);
- info.AddValue("encoderFallback", this.EncoderFallback);
- info.AddValue("decoderFallback", this.DecoderFallback);
-
- // These were in Everett V1.1 as well
- info.AddValue("m_codePage", this.m_codePage);
-
- // This was unique to Everett V1.1
- info.AddValue("dataItem", null);
-
- // Everett duplicated these fields, so these are needed for portability
- info.AddValue("Encoding+m_codePage", this.m_codePage);
- info.AddValue("Encoding+dataItem", null);
- }
-
- #endregion Serialization
-
// Converts a byte array from one encoding to another. The bytes in the
// bytes array are converted from srcEncoding to
// dstEncoding, and the returned value is a new byte array
private void GetDataItem()
{
- if (dataItem == null)
+ if (_dataItem == null)
{
- dataItem = EncodingTable.GetCodePageDataItem(m_codePage);
- if (dataItem == null)
+ _dataItem = EncodingTable.GetCodePageDataItem(_codePage);
+ if (_dataItem == null)
{
- throw new NotSupportedException(
- SR.Format(SR.NotSupported_NoCodepageData, m_codePage));
+ throw new NotSupportedException(SR.Format(SR.NotSupported_NoCodepageData, _codePage));
}
}
}
{
get
{
- if (dataItem == null)
+ if (_dataItem == null)
{
GetDataItem();
}
- return (dataItem.BodyName);
+ return (_dataItem.BodyName);
}
}
{
get
{
- return SR.GetResourceString("Globalization_cp_" + m_codePage.ToString());
+ return SR.GetResourceString("Globalization_cp_" + _codePage.ToString());
}
}
#endif
{
get
{
- if (dataItem == null)
+ if (_dataItem == null)
{
GetDataItem();
}
- return (dataItem.HeaderName);
+ return (_dataItem.HeaderName);
}
}
{
get
{
- if (dataItem == null)
+ if (_dataItem == null)
{
GetDataItem();
}
- return (dataItem.WebName);
+ return (_dataItem.WebName);
}
}
{
get
{
- if (dataItem == null)
+ if (_dataItem == null)
{
GetDataItem();
}
- return (dataItem.UIFamilyCodePage);
+ return (_dataItem.UIFamilyCodePage);
}
}
{
get
{
- if (dataItem == null)
+ if (_dataItem == null)
{
GetDataItem();
}
- return ((dataItem.Flags & MIMECONTF_BROWSER) != 0);
+ return ((_dataItem.Flags & MIMECONTF_BROWSER) != 0);
}
}
{
get
{
- if (dataItem == null)
+ if (_dataItem == null)
{
GetDataItem();
}
- return ((dataItem.Flags & MIMECONTF_SAVABLE_BROWSER) != 0);
+ return ((_dataItem.Flags & MIMECONTF_SAVABLE_BROWSER) != 0);
}
}
{
get
{
- if (dataItem == null)
+ if (_dataItem == null)
{
GetDataItem();
}
- return ((dataItem.Flags & MIMECONTF_MAILNEWS) != 0);
+ return ((_dataItem.Flags & MIMECONTF_MAILNEWS) != 0);
}
}
{
get
{
- if (dataItem == null)
+ if (_dataItem == null)
{
GetDataItem();
}
- return ((dataItem.Flags & MIMECONTF_SAVABLE_MAILNEWS) != 0);
+ return ((_dataItem.Flags & MIMECONTF_SAVABLE_MAILNEWS) != 0);
}
}
Encoding newEncoding = (Encoding)this.MemberwiseClone();
// New one should be readable
- newEncoding.m_isReadOnly = false;
+ newEncoding._isReadOnly = false;
return newEncoding;
}
{
get
{
- return (m_isReadOnly);
+ return (_isReadOnly);
}
}
// GetCharCount method can be used to determine the exact number of
// characters that will be produced for a given range of bytes.
// Alternatively, the GetMaxCharCount method can be used to
- // determine the maximum number of characterss that will be produced for a
+ // determine the maximum number of characters that will be produced for a
// given number of bytes, regardless of the actual byte values.
//
{
get
{
- return m_codePage;
+ return _codePage;
}
}
{
Encoding that = value as Encoding;
if (that != null)
- return (m_codePage == that.m_codePage) &&
+ return (_codePage == that._codePage) &&
(EncoderFallback.Equals(that.EncoderFallback)) &&
(DecoderFallback.Equals(that.DecoderFallback));
return (false);
public override int GetHashCode()
{
- return m_codePage + this.EncoderFallback.GetHashCode() + this.DecoderFallback.GetHashCode();
+ return _codePage + this.EncoderFallback.GetHashCode() + this.DecoderFallback.GetHashCode();
}
internal virtual char[] GetBestFitUnicodeToBytesData()
internal void ThrowBytesOverflow()
{
// Special message to include fallback type in case fallback's GetMaxCharCount is broken
- // This happens if user has implimented an encoder fallback with a broken GetMaxCharCount
+ // This happens if user has implemented an encoder fallback with a broken GetMaxCharCount
throw new ArgumentException(
SR.Format(SR.Argument_EncodingConversionOverflowBytes, EncodingName, EncoderFallback.GetType()), "bytes");
}
internal void ThrowBytesOverflow(EncoderNLS encoder, bool nothingEncoded)
{
- if (encoder == null || encoder.m_throwOnOverflow || nothingEncoded)
+ if (encoder == null || encoder._throwOnOverflow || nothingEncoded)
{
if (encoder != null && encoder.InternalHasFallbackBuffer)
encoder.FallbackBuffer.InternalReset();
// Special message to include fallback type in case fallback's GetMaxCharCount is broken
- // This happens if user has implimented an encoder fallback with a broken GetMaxCharCount
+ // This happens if user has implemented an encoder fallback with a broken GetMaxCharCount
ThrowBytesOverflow();
}
internal void ThrowCharsOverflow()
{
// Special message to include fallback type in case fallback's GetMaxCharCount is broken
- // This happens if user has implimented a decoder fallback with a broken GetMaxCharCount
+ // This happens if user has implemented a decoder fallback with a broken GetMaxCharCount
throw new ArgumentException(
SR.Format(SR.Argument_EncodingConversionOverflowChars, EncodingName, DecoderFallback.GetType()), "chars");
}
internal void ThrowCharsOverflow(DecoderNLS decoder, bool nothingDecoded)
{
- if (decoder == null || decoder.m_throwOnOverflow || nothingDecoded)
+ if (decoder == null || decoder._throwOnOverflow || nothingDecoded)
{
if (decoder != null && decoder.InternalHasFallbackBuffer)
decoder.FallbackBuffer.InternalReset();
// Special message to include fallback type in case fallback's GetMaxCharCount is broken
- // This happens if user has implimented a decoder fallback with a broken GetMaxCharCount
+ // This happens if user has implemented a decoder fallback with a broken GetMaxCharCount
ThrowCharsOverflow();
}
decoder.ClearMustFlush();
}
- internal sealed class DefaultEncoder : Encoder, IObjectReference, ISerializable
+ internal sealed class DefaultEncoder : Encoder, IObjectReference
{
- private Encoding m_encoding;
+ private Encoding _encoding;
public DefaultEncoder(Encoding encoding)
{
- m_encoding = encoding;
+ _encoding = encoding;
}
public Object GetRealObject(StreamingContext context)
throw new PlatformNotSupportedException();
}
- // ISerializable implementation, get data for this object
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
// Returns the number of bytes the next call to GetBytes will
// produce if presented with the given range of characters and the given
// value of the flush parameter. The returned value takes into
public override int GetByteCount(char[] chars, int index, int count, bool flush)
{
- return m_encoding.GetByteCount(chars, index, count);
+ return _encoding.GetByteCount(chars, index, count);
}
[SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public unsafe override int GetByteCount(char* chars, int count, bool flush)
{
- return m_encoding.GetByteCount(chars, count);
+ return _encoding.GetByteCount(chars, count);
}
// Encodes a range of characters in a character array into a range of bytes
public override int GetBytes(char[] chars, int charIndex, int charCount,
byte[] bytes, int byteIndex, bool flush)
{
- return m_encoding.GetBytes(chars, charIndex, charCount, bytes, byteIndex);
+ return _encoding.GetBytes(chars, charIndex, charCount, bytes, byteIndex);
}
[SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public unsafe override int GetBytes(char* chars, int charCount,
byte* bytes, int byteCount, bool flush)
{
- return m_encoding.GetBytes(chars, charCount, bytes, byteCount);
+ return _encoding.GetBytes(chars, charCount, bytes, byteCount);
}
}
- internal sealed class DefaultDecoder : Decoder, IObjectReference, ISerializable
+ internal sealed class DefaultDecoder : Decoder, IObjectReference
{
- private Encoding m_encoding;
+ private Encoding _encoding;
public DefaultDecoder(Encoding encoding)
{
- m_encoding = encoding;
+ _encoding = encoding;
}
public Object GetRealObject(StreamingContext context)
throw new PlatformNotSupportedException();
}
- // ISerializable implementation
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
// Returns the number of characters the next call to GetChars will
// produce if presented with the given range of bytes. The returned value
// takes into account the state in which the decoder was left following the
public override int GetCharCount(byte[] bytes, int index, int count, bool flush)
{
- return m_encoding.GetCharCount(bytes, index, count);
+ return _encoding.GetCharCount(bytes, index, count);
}
[SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public unsafe override int GetCharCount(byte* bytes, int count, bool flush)
{
// By default just call the encoding version, no flush by default
- return m_encoding.GetCharCount(bytes, count);
+ return _encoding.GetCharCount(bytes, count);
}
// Decodes a range of bytes in a byte array into a range of characters
public override int GetChars(byte[] bytes, int byteIndex, int byteCount,
char[] chars, int charIndex, bool flush)
{
- return m_encoding.GetChars(bytes, byteIndex, byteCount, chars, charIndex);
+ return _encoding.GetChars(bytes, byteIndex, byteCount, chars, charIndex);
}
[SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
char* chars, int charCount, bool flush)
{
// By default just call the encoding's version
- return m_encoding.GetChars(bytes, byteCount, chars, charCount);
+ return _encoding.GetChars(bytes, byteCount, chars, charCount);
}
}
{
this.fallbackBuffer = _encoder.FallbackBuffer;
// If we're not converting we must not have data in our fallback buffer
- if (_encoder.m_throwOnOverflow && _encoder.InternalHasFallbackBuffer &&
+ if (_encoder._throwOnOverflow && _encoder.InternalHasFallbackBuffer &&
this.fallbackBuffer.Remaining > 0)
throw new ArgumentException(SR.Format(SR.Argument_EncoderFallbackNotEmpty,
_encoder.Encoding.EncodingName, _encoder.Fallback.GetType()));