Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 30d20fd

Browse files
authored
Delete unused leftovers from binary serialization (#15140)
1 parent e1a82f1 commit 30d20fd

File tree

12 files changed

+25
-345
lines changed

12 files changed

+25
-345
lines changed

src/mscorlib/shared/System/Globalization/DateTimeFormatInfo.cs

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Collections.Generic;
66
using System.Diagnostics;
77
using System.Runtime.CompilerServices;
8-
using System.Runtime.Serialization;
98

109
namespace System.Globalization
1110
{
@@ -56,24 +55,18 @@ public sealed class DateTimeFormatInfo : IFormatProvider, ICloneable
5655
private static volatile DateTimeFormatInfo s_invariantInfo;
5756

5857
// an index which points to a record in Culture Data Table.
59-
[NonSerialized]
6058
private CultureData _cultureData;
6159

6260
// The culture name used to create this DTFI.
63-
64-
[OptionalField(VersionAdded = 2)]
6561
private String _name = null;
6662

6763
// The language name of the culture used to create this DTFI.
68-
[NonSerialized]
6964
private String _langName = null;
7065

7166
// CompareInfo usually used by the parser.
72-
[NonSerialized]
7367
private CompareInfo _compareInfo = null;
7468

7569
// Culture matches current DTFI. mainly used for string comparisons during parsing.
76-
[NonSerialized]
7770
private CultureInfo _cultureInfo = null;
7871

7972
//
@@ -147,7 +140,6 @@ public sealed class DateTimeFormatInfo : IFormatProvider, ICloneable
147140
private String longTimePattern = null;
148141
private String shortTimePattern = null;
149142

150-
[OptionalField(VersionAdded = 3)]
151143
private String[] allYearMonthPatterns = null;
152144

153145
private String[] allShortDatePatterns = null;
@@ -347,73 +339,13 @@ private void InitializeOverridableProperties(CultureData cultureData, CalendarId
347339
Debug.Assert(this.allYearMonthPatterns.Length > 0, "[DateTimeFormatInfo.Populate] Expected some year month patterns");
348340
}
349341

350-
[OptionalField(VersionAdded = 1)]
351342
private bool _useUserOverride;
352343

353344
// This was synthesized by Whidbey so we knew what words might appear in the middle of a date string
354345
// Now we always synthesize so its not helpful
355346

356347
internal String[] m_dateWords = null;
357348

358-
[OnSerializing]
359-
private void OnSerializing(StreamingContext ctx)
360-
{
361-
_name = this.CultureName; // make sure the _name is initialized.
362-
_useUserOverride = _cultureData.UseUserOverride;
363-
364-
// Important to initialize these fields otherwise we may run into exception when deserializing on Whidbey
365-
// because Whidbey try to initialize some of these fields using calendar data which could be null values
366-
// and then we get exceptions. So we call the accessors to force the caches to get loaded.
367-
Object o;
368-
o = this.LongTimePattern;
369-
o = this.LongDatePattern;
370-
o = this.ShortTimePattern;
371-
o = this.ShortDatePattern;
372-
o = this.YearMonthPattern;
373-
o = this.AllLongTimePatterns;
374-
o = this.AllLongDatePatterns;
375-
o = this.AllShortTimePatterns;
376-
o = this.AllShortDatePatterns;
377-
o = this.AllYearMonthPatterns;
378-
}
379-
380-
[OnDeserialized]
381-
private void OnDeserialized(StreamingContext ctx)
382-
{
383-
if (_name != null)
384-
{
385-
_cultureData = CultureData.GetCultureData(_name, _useUserOverride);
386-
if (_cultureData == null)
387-
{
388-
throw new CultureNotFoundException("_name", _name, SR.Argument_CultureNotSupported);
389-
}
390-
}
391-
392-
if (calendar == null)
393-
{
394-
calendar = (Calendar)GregorianCalendar.GetDefaultInstance().Clone();
395-
calendar.SetReadOnlyState(_isReadOnly);
396-
}
397-
398-
InitializeOverridableProperties(_cultureData, calendar.ID);
399-
400-
//
401-
// turn off read only state till we finish initializing all fields and then store read only state after we are done.
402-
//
403-
bool isReadOnly = _isReadOnly;
404-
_isReadOnly = false;
405-
406-
// If we deserialized defaults ala Whidbey, make sure they're still defaults
407-
// Whidbey's arrays could get a bit mixed up.
408-
if (longDatePattern != null) this.LongDatePattern = longDatePattern;
409-
if (shortDatePattern != null) this.ShortDatePattern = shortDatePattern;
410-
if (yearMonthPattern != null) this.YearMonthPattern = yearMonthPattern;
411-
if (longTimePattern != null) this.LongTimePattern = longTimePattern;
412-
if (shortTimePattern != null) this.ShortTimePattern = shortTimePattern;
413-
414-
_isReadOnly = isReadOnly;
415-
}
416-
417349
// Returns a default DateTimeFormatInfo that will be universally
418350
// supported and constant irrespective of the current culture.
419351
// Used by FromString methods.
@@ -2094,7 +2026,6 @@ public String[] MonthGenitiveNames
20942026
//
20952027
// Positive TimeSpan Pattern
20962028
//
2097-
[NonSerialized]
20982029
private string _fullTimeSpanPositivePattern;
20992030
internal String FullTimeSpanPositivePattern
21002031
{
@@ -2118,7 +2049,6 @@ internal String FullTimeSpanPositivePattern
21182049
//
21192050
// Negative TimeSpan Pattern
21202051
//
2121-
[NonSerialized]
21222052
private string _fullTimeSpanNegativePattern;
21232053
internal String FullTimeSpanNegativePattern
21242054
{
@@ -2269,7 +2199,6 @@ internal Boolean YearMonthAdjustment(ref int year, ref int month, Boolean parsed
22692199
//
22702200
// DateTimeFormatInfo tokenizer. This is used by DateTime.Parse() to break input string into tokens.
22712201
//
2272-
[NonSerialized]
22732202
private TokenHashValue[] _dtfiTokenHash;
22742203

22752204
private const int TOKEN_HASH_SIZE = 199;

src/mscorlib/shared/System/Globalization/NumberFormatInfo.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
using System.Runtime.Serialization;
76
using System.Text;
87

98
namespace System.Globalization
@@ -69,7 +68,6 @@ sealed public class NumberFormatInfo : IFormatProvider, ICloneable
6968
internal String perMilleSymbol = "\u2030";
7069

7170

72-
[OptionalField(VersionAdded = 2)]
7371
internal String[] nativeDigits = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
7472

7573
internal int numberDecimalDigits = 2;
@@ -81,29 +79,17 @@ sealed public class NumberFormatInfo : IFormatProvider, ICloneable
8179
internal int percentNegativePattern = 0;
8280
internal int percentDecimalDigits = 2;
8381

84-
[OptionalField(VersionAdded = 2)]
8582
internal int digitSubstitution = (int)DigitShapes.None;
8683

8784
internal bool isReadOnly = false;
8885

8986
// Is this NumberFormatInfo for invariant culture?
90-
91-
[OptionalField(VersionAdded = 2)]
9287
internal bool m_isInvariant = false;
9388

9489
public NumberFormatInfo() : this(null)
9590
{
9691
}
9792

98-
[OnSerializing]
99-
private void OnSerializing(StreamingContext ctx) { }
100-
101-
[OnDeserializing]
102-
private void OnDeserializing(StreamingContext ctx) { }
103-
104-
[OnDeserialized]
105-
private void OnDeserialized(StreamingContext ctx) { }
106-
10793
private static void VerifyDecimalSeparator(String decSep, String propertyName)
10894
{
10995
if (decSep == null)

src/mscorlib/shared/System/Globalization/SortKey.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
using System;
1515
using System.Runtime.CompilerServices;
16-
using System.Runtime.Serialization;
1716
using System.Diagnostics;
1817

1918
namespace System.Globalization
@@ -24,12 +23,8 @@ public partial class SortKey
2423
// Internal Information //
2524
//--------------------------------------------------------------------//
2625

27-
[OptionalField(VersionAdded = 3)]
2826
internal string _localeName; // locale identifier
2927

30-
[OptionalField(VersionAdded = 1)] // LCID field so serialization is Whidbey compatible though we don't officially support it
31-
internal int _win32LCID;
32-
3328
internal CompareOptions _options; // options
3429
internal string _string; // original string
3530
internal byte[] _keyData; // sortkey data
@@ -46,26 +41,6 @@ internal SortKey(String localeName, String str, CompareOptions options, byte[] k
4641
_string = str;
4742
}
4843

49-
[OnSerializing]
50-
private void OnSerializing(StreamingContext context)
51-
{
52-
//set LCID to proper value for Whidbey serialization (no other use)
53-
if (_win32LCID == 0)
54-
{
55-
_win32LCID = CultureInfo.GetCultureInfo(_localeName).LCID;
56-
}
57-
}
58-
59-
[OnDeserialized]
60-
private void OnDeserialized(StreamingContext context)
61-
{
62-
//set locale name to proper value after Whidbey deserialization
63-
if (String.IsNullOrEmpty(_localeName) && _win32LCID != 0)
64-
{
65-
_localeName = CultureInfo.GetCultureInfo(_win32LCID).Name;
66-
}
67-
}
68-
6944
////////////////////////////////////////////////////////////////////////
7045
//
7146
// GetOriginalString

src/mscorlib/shared/System/Globalization/StringInfo.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@
1414

1515
using System;
1616
using System.Diagnostics;
17-
using System.Runtime.Serialization;
1817

1918
namespace System.Globalization
2019
{
2120
public class StringInfo
2221
{
23-
[OptionalField(VersionAdded = 2)]
2422
private string _str;
2523

26-
[NonSerialized]
2724
private int[] _indexes;
2825

2926
// Legacy constructor
@@ -35,21 +32,6 @@ public StringInfo(string value)
3532
this.String = value;
3633
}
3734

38-
[OnDeserializing]
39-
private void OnDeserializing(StreamingContext ctx)
40-
{
41-
_str = String.Empty;
42-
}
43-
44-
[OnDeserialized]
45-
private void OnDeserialized(StreamingContext ctx)
46-
{
47-
if (_str.Length == 0)
48-
{
49-
_indexes = null;
50-
}
51-
}
52-
5335
public override bool Equals(Object value)
5436
{
5537
StringInfo that = value as StringInfo;

src/mscorlib/shared/System/Lazy.cs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
using System.Diagnostics;
1616
using System.Runtime.ExceptionServices;
1717
using System.Runtime.InteropServices;
18-
using System.Runtime.Serialization;
1918
using System.Threading;
2019

2120
namespace System
@@ -191,17 +190,15 @@ private static T CreateViaDefaultConstructor()
191190
return (T)LazyHelper.CreateViaDefaultConstructor(typeof(T));
192191
}
193192

194-
// _state, a volatile reference, is set to null after m_value has been set
195-
[NonSerialized]
193+
// _state, a volatile reference, is set to null after _value has been set
196194
private volatile LazyHelper _state;
197195

198196
// we ensure that _factory when finished is set to null to allow garbage collector to clean up
199197
// any referenced items
200-
[NonSerialized]
201198
private Func<T> _factory;
202199

203200
// _value eventually stores the lazily created value. It is valid when _state = null.
204-
private T m_value; // Do not rename (binary serialization)
201+
private T _value;
205202

206203
/// <summary>
207204
/// Initializes a new instance of the <see cref="T:System.Threading.Lazy{T}"/> class that
@@ -225,7 +222,7 @@ public Lazy()
225222
/// </remarks>
226223
public Lazy(T value)
227224
{
228-
m_value = value;
225+
_value = value;
229226
}
230227

231228
/// <summary>
@@ -311,7 +308,7 @@ private Lazy(Func<T> valueFactory, LazyThreadSafetyMode mode, bool useDefaultCon
311308

312309
private void ViaConstructor()
313310
{
314-
m_value = CreateViaDefaultConstructor();
311+
_value = CreateViaDefaultConstructor();
315312
_state = null; // volatile write, must occur after setting _value
316313
}
317314

@@ -324,7 +321,7 @@ private void ViaFactory(LazyThreadSafetyMode mode)
324321
throw new InvalidOperationException(SR.Lazy_Value_RecursiveCallsToValue);
325322
_factory = null;
326323

327-
m_value = factory();
324+
_value = factory();
328325
_state = null; // volatile write, must occur after setting _value
329326
}
330327
catch (Exception exception)
@@ -360,7 +357,7 @@ private void PublicationOnly(LazyHelper publicationOnly, T possibleValue)
360357
if (previous == publicationOnly)
361358
{
362359
_factory = null;
363-
m_value = possibleValue;
360+
_value = possibleValue;
364361
_state = null; // volatile write, must occur after setting _value
365362
}
366363
}
@@ -439,15 +436,6 @@ private T CreateValue()
439436
return Value;
440437
}
441438

442-
/// <summary>Forces initialization during serialization.</summary>
443-
/// <param name="context">The StreamingContext for the serialization operation.</param>
444-
[OnSerializing]
445-
private void OnSerializing(StreamingContext context)
446-
{
447-
// Force initialization
448-
T dummy = Value;
449-
}
450-
451439
/// <summary>Creates and returns a string representation of this instance.</summary>
452440
/// <returns>The result of calling <see cref="System.Object.ToString"/> on the <see
453441
/// cref="Value"/>.</returns>
@@ -468,7 +456,7 @@ internal T ValueForDebugDisplay
468456
{
469457
return default(T);
470458
}
471-
return m_value;
459+
return _value;
472460
}
473461
}
474462

@@ -515,7 +503,7 @@ internal T ValueForDebugDisplay
515503
/// from initialization delegate.
516504
/// </remarks>
517505
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
518-
public T Value => _state == null ? m_value : CreateValue();
506+
public T Value => _state == null ? _value : CreateValue();
519507
}
520508

521509
/// <summary>A debugger view of the Lazy&lt;T&gt; to surface additional debugging properties and

src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@ namespace System.Collections.ObjectModel
2323
internal class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary, IReadOnlyDictionary<TKey, TValue>
2424
{
2525
private readonly IDictionary<TKey, TValue> m_dictionary;
26-
[NonSerialized]
2726
private Object m_syncRoot;
28-
[NonSerialized]
2927
private KeyCollection m_keys;
30-
[NonSerialized]
3128
private ValueCollection m_values;
3229

3330
public ReadOnlyDictionary(IDictionary<TKey, TValue> dictionary)
@@ -429,7 +426,6 @@ IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values
429426
public sealed class KeyCollection : ICollection<TKey>, ICollection, IReadOnlyCollection<TKey>
430427
{
431428
private readonly ICollection<TKey> m_collection;
432-
[NonSerialized]
433429
private Object m_syncRoot;
434430

435431
internal KeyCollection(ICollection<TKey> collection)
@@ -539,7 +535,6 @@ object ICollection.SyncRoot
539535
public sealed class ValueCollection : ICollection<TValue>, ICollection, IReadOnlyCollection<TValue>
540536
{
541537
private readonly ICollection<TValue> m_collection;
542-
[NonSerialized]
543538
private Object m_syncRoot;
544539

545540
internal ValueCollection(ICollection<TValue> collection)

0 commit comments

Comments
 (0)