mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-22 19:10:41 -10:00
Scale back [Serializable] CoreFX types (dotnet/corefx#19742)
* Remove SerializableAttribute from many CoreFX types that will not be serializable. * Removes serialization tests for types that are no longer serializable and fixes serializing a couple of types. Includes marking some internal serializable types as public so that they'll be reflectible with .NET Native. * Remove unneeded pragmas * Update based on review comments Commit migrated from https://github.com/dotnet/corefx/commit/6dd451f51451a7d0ceea6104b51bd17005e9a0e6
This commit is contained in:
1 parent
8ab7794e6c
commit
975ad3c685
460 files changed
+42
-858
No files matched your search
@@ -41,7 +41,6 @@ namespace System.Text
|
||||
// WORD byteReplace; // 2 bytes = 48 // default replacement byte(s)
|
||||
// BYTE[] data; // data section
|
||||
// }
|
||||
[Serializable]
|
||||
internal abstract class BaseCodePageEncoding : EncodingNLS, ISerializable
|
||||
{
|
||||
internal const String CODE_PAGE_DATA_FILE_NAME = "codepages.nlp";
|
||||
|
||||
@@ -14,7 +14,6 @@ namespace System.Text
|
||||
{
|
||||
// DBCSCodePageEncoding
|
||||
//
|
||||
[Serializable]
|
||||
internal class DBCSCodePageEncoding : BaseCodePageEncoding
|
||||
{
|
||||
// Pointers to our memory section parts
|
||||
@@ -1161,7 +1160,6 @@ namespace System.Text
|
||||
return new DBCSDecoder(this);
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal class DBCSDecoder : DecoderNLS
|
||||
{
|
||||
// Need a place for the last left over byte
|
||||
|
||||
@@ -13,7 +13,6 @@ using System.Diagnostics;
|
||||
|
||||
namespace System.Text
|
||||
{
|
||||
[Serializable]
|
||||
internal sealed class InternalDecoderBestFitFallback : DecoderFallback
|
||||
{
|
||||
// Our variables
|
||||
|
||||
@@ -21,7 +21,6 @@ namespace System.Text
|
||||
// class are typically obtained through calls to the GetDecoder method
|
||||
// of Encoding objects.
|
||||
//
|
||||
[Serializable]
|
||||
internal class DecoderNLS : Decoder, ISerializable
|
||||
{
|
||||
// Remember our encoding
|
||||
@@ -53,7 +52,6 @@ namespace System.Text
|
||||
info.SetType(typeof(DecoderNLSSurrogate));
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal sealed class DecoderNLSSurrogate : IObjectReference, ISerializable
|
||||
{
|
||||
internal const string EncodingKey = "Encoding";
|
||||
|
||||
@@ -45,7 +45,6 @@ using System;
|
||||
|
||||
namespace System.Text
|
||||
{
|
||||
[Serializable]
|
||||
internal class EUCJPEncoding : DBCSCodePageEncoding
|
||||
{
|
||||
// This pretends to be CP 932 as far as memory tables are concerned.
|
||||
|
||||
@@ -15,7 +15,6 @@ using System.Threading;
|
||||
|
||||
namespace System.Text
|
||||
{
|
||||
[Serializable]
|
||||
internal class InternalEncoderBestFitFallback : EncoderFallback
|
||||
{
|
||||
// Our variables
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace System.Text
|
||||
// class are typically obtained through calls to the GetEncoder method
|
||||
// of Encoding objects.
|
||||
//
|
||||
[Serializable]
|
||||
internal class EncoderNLS : Encoder, ISerializable
|
||||
{
|
||||
// Need a place for the last left over character, most of our encodings use this
|
||||
@@ -49,7 +48,6 @@ namespace System.Text
|
||||
info.SetType(typeof(EncoderNLSSurrogate));
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal sealed class EncoderNLSSurrogate : ISerializable, IObjectReference
|
||||
{
|
||||
internal const string EncodingKey = "Encoding";
|
||||
|
||||
@@ -21,7 +21,6 @@ namespace System.Text
|
||||
// encodings.
|
||||
// So if you change the wrappers in this class, you must change the wrappers in the other classes
|
||||
// as well because they should have the same behavior.
|
||||
[Serializable]
|
||||
internal abstract class EncodingNLS : Encoding
|
||||
{
|
||||
private string _encodingName;
|
||||
@@ -580,7 +579,6 @@ namespace System.Text
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
protected sealed class CodePageEncodingSurrogate : ISerializable, IObjectReference
|
||||
{
|
||||
internal const string CodePageKey = "CodePage";
|
||||
|
||||
@@ -101,7 +101,6 @@ namespace System.Text
|
||||
**
|
||||
==============================================================================*/
|
||||
|
||||
[Serializable]
|
||||
internal sealed class GB18030Encoding : DBCSCodePageEncoding
|
||||
{
|
||||
// This is the table of 4 byte conversions.
|
||||
@@ -795,7 +794,6 @@ namespace System.Text
|
||||
return new GB18030Decoder(this);
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal sealed class GB18030Decoder : DecoderNLS
|
||||
{
|
||||
internal short bLeftOver1 = -1;
|
||||
|
||||
@@ -28,7 +28,6 @@ namespace System.Text
|
||||
// Forms D & KD have things like 0934, which decomposes to 0933 + 093C, so not normal.
|
||||
// Form IDNA has the above problems plus case mapping, so false (like most encodings)
|
||||
//
|
||||
[Serializable]
|
||||
internal class ISCIIEncoding : EncodingNLS, ISerializable
|
||||
{
|
||||
// Constants
|
||||
@@ -717,7 +716,6 @@ namespace System.Text
|
||||
return _defaultCodePage + EncoderFallback.GetHashCode() + DecoderFallback.GetHashCode();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal class ISCIIEncoder : EncoderNLS
|
||||
{
|
||||
// Need to remember the default code page (for HasState)
|
||||
@@ -756,7 +754,6 @@ namespace System.Text
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal class ISCIIDecoder : DecoderNLS
|
||||
{
|
||||
// Need a place to store any our current code page and last ATR flag
|
||||
|
||||
@@ -49,7 +49,6 @@ namespace System.Text
|
||||
**
|
||||
==============================================================================*/
|
||||
|
||||
[Serializable]
|
||||
internal class ISO2022Encoding : DBCSCodePageEncoding
|
||||
{
|
||||
private const byte SHIFT_OUT = (byte)0x0E;
|
||||
@@ -1805,7 +1804,6 @@ namespace System.Text
|
||||
return new ISO2022Decoder(this);
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal class ISO2022Encoder : System.Text.EncoderNLS
|
||||
{
|
||||
internal ISO2022Modes currentMode;
|
||||
@@ -1838,7 +1836,6 @@ namespace System.Text
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal class ISO2022Decoder : System.Text.DecoderNLS
|
||||
{
|
||||
internal byte[] bytesLeftOver;
|
||||
|
||||
@@ -13,7 +13,6 @@ using System.Security;
|
||||
|
||||
namespace System.Text
|
||||
{
|
||||
[Serializable]
|
||||
internal class SBCSCodePageEncoding : BaseCodePageEncoding
|
||||
{
|
||||
// Pointers to our memory section parts
|
||||
|
||||
@@ -495,9 +495,6 @@ namespace System.Text.Tests
|
||||
Assert.Equal(encoding.CodePage, (int)mapping[0]);
|
||||
Assert.Equal(encoding.WebName, (string)mapping[1]);
|
||||
|
||||
// If available, validate serializing and deserializing with BinaryFormatter
|
||||
ValidateSerializeDeserialize(encoding);
|
||||
|
||||
// Get encoding via query string.
|
||||
Assert.Equal(Encoding.GetEncoding((string)mapping[2]), CodePagesEncodingProvider.Instance.GetEncoding((string)mapping[2]));
|
||||
}
|
||||
@@ -515,47 +512,6 @@ namespace System.Text.Tests
|
||||
Assert.Contains(mappedEncoding, CrossplatformDefaultEncodings().Union(CodePageInfo().Select(i => Map((int)i[0], (string)i[1]))));
|
||||
}
|
||||
|
||||
static void ValidateSerializeDeserialize(Encoding e)
|
||||
{
|
||||
// Make sure the Encoding roundtrips
|
||||
Assert.Equal(e, BinaryFormatterHelpers.Clone(e));
|
||||
|
||||
// Get an encoder and decoder from the encoding, and clone them
|
||||
Encoder origEncoder = e.GetEncoder();
|
||||
Decoder origDecoder = e.GetDecoder();
|
||||
Encoder clonedEncoder = BinaryFormatterHelpers.Clone(origEncoder);
|
||||
Decoder clonedDecoder = BinaryFormatterHelpers.Clone(origDecoder);
|
||||
|
||||
// Encode and decode some text with each pairing
|
||||
const string InputText = "abcdefghijklmnopqrstuvwxyz";
|
||||
char[] inputTextChars = InputText.ToCharArray();
|
||||
var pairs = new[]
|
||||
{
|
||||
Tuple.Create(origEncoder, origDecoder),
|
||||
Tuple.Create(origEncoder, clonedDecoder),
|
||||
Tuple.Create(clonedEncoder, origDecoder),
|
||||
Tuple.Create(clonedEncoder, clonedDecoder),
|
||||
};
|
||||
var results = new List<char[]>();
|
||||
foreach (Tuple<Encoder, Decoder> pair in pairs)
|
||||
{
|
||||
byte[] encodedBytes = new byte[pair.Item1.GetByteCount(inputTextChars, 0, inputTextChars.Length, true)];
|
||||
Assert.Equal(encodedBytes.Length, pair.Item1.GetBytes(inputTextChars, 0, inputTextChars.Length, encodedBytes, 0, true));
|
||||
char[] decodedChars = new char[pair.Item2.GetCharCount(encodedBytes, 0, encodedBytes.Length)];
|
||||
Assert.Equal(decodedChars.Length, pair.Item2.GetChars(encodedBytes, 0, encodedBytes.Length, decodedChars, 0));
|
||||
results.Add(decodedChars);
|
||||
}
|
||||
|
||||
// Validate that all of the pairings produced the same results
|
||||
foreach (char[] a in results)
|
||||
{
|
||||
foreach (char[] b in results)
|
||||
{
|
||||
Assert.Equal(a, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ValidateDefaultEncodings()
|
||||
{
|
||||
foreach (var mapping in CrossplatformDefaultEncodings())
|
||||
|
||||
Reference in new issue
Block a user