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

Commit 81d852c

Browse files
ViktorHoferdanmoseley
authored andcommitted
Cross Serialization Cleanup (#21067)
* Remove serialization from namevalucollection types * Update blobs
1 parent a405d4d commit 81d852c

File tree

3 files changed

+7
-159
lines changed

3 files changed

+7
-159
lines changed

src/System.Collections.Specialized/src/System/Collections/Specialized/NameObjectCollectionBase.cs

Lines changed: 3 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,15 @@ namespace System.Collections.Specialized
2121
/// and <see cref='System.Object' qualify='true'/> values that can be accessed either with the hash code of
2222
/// the key or with the index.</para>
2323
/// </devdoc>
24-
[Serializable]
25-
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
2624
public abstract class NameObjectCollectionBase : ICollection, ISerializable, IDeserializationCallback
2725
{
28-
// const names used for serialization
29-
private const String ReadOnlyName = "ReadOnly"; // Do not rename (binary serialization)
30-
private const String CountName = "Count"; // Do not rename (binary serialization)
31-
private const String ComparerName = "Comparer"; // Do not rename (binary serialization)
32-
private const String HashCodeProviderName = "HashProvider"; // Do not rename (binary serialization)
33-
private const String KeysName = "Keys"; // Do not rename (binary serialization)
34-
private const String ValuesName = "Values"; // Do not rename (binary serialization)
35-
private const String KeyComparerName = "KeyComparer"; // Do not rename (binary serialization)
36-
private const String VersionName = "Version"; // Do not rename (binary serialization)
37-
3826
private bool _readOnly = false;
3927
private ArrayList _entriesArray;
4028
private IEqualityComparer _keyComparer;
4129
private volatile Hashtable _entriesTable;
4230
private volatile NameObjectEntry _nullKeyEntry;
4331
private KeysCollection _keys;
4432
private int _version;
45-
private SerializationInfo _serializationInfo;
46-
[NonSerialized]
4733
private Object _syncRoot;
4834

4935
private static readonly StringComparer s_defaultComparer = CultureInfo.InvariantCulture.CompareInfo.GetStringComparer(CompareOptions.IgnoreCase);
@@ -92,146 +78,17 @@ protected NameObjectCollectionBase(int capacity)
9278

9379
protected NameObjectCollectionBase(SerializationInfo info, StreamingContext context)
9480
{
95-
_serializationInfo = info;
81+
throw new PlatformNotSupportedException();
9682
}
9783

9884
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
9985
{
100-
if (info == null)
101-
{
102-
throw new ArgumentNullException(nameof(info));
103-
}
104-
105-
info.AddValue(ReadOnlyName, _readOnly);
106-
107-
// Maintain backward serialization compatibility if new APIs are not used.
108-
if (_keyComparer == s_defaultComparer)
109-
{
110-
info.AddValue(HashCodeProviderName, CaseInsensitiveHashCodeProvider.DefaultInvariant, typeof(IHashCodeProvider));
111-
info.AddValue(ComparerName, CaseInsensitiveComparer.DefaultInvariant, typeof(IComparer));
112-
}
113-
else if (_keyComparer == null)
114-
{
115-
info.AddValue(HashCodeProviderName, null, typeof(IHashCodeProvider));
116-
info.AddValue(ComparerName, null, typeof(IComparer));
117-
}
118-
else if (_keyComparer is CompatibleComparer)
119-
{
120-
CompatibleComparer c = (CompatibleComparer)_keyComparer;
121-
info.AddValue(HashCodeProviderName, c.HashCodeProvider, typeof(IHashCodeProvider));
122-
info.AddValue(ComparerName, c.Comparer, typeof(IComparer));
123-
}
124-
else
125-
{
126-
info.AddValue(KeyComparerName, _keyComparer, typeof(IEqualityComparer));
127-
}
128-
129-
int count = _entriesArray.Count;
130-
info.AddValue(CountName, count);
131-
132-
string[] keys = new string[count];
133-
object[] values = new object[count];
134-
135-
for (int i = 0; i < count; i++)
136-
{
137-
NameObjectEntry entry = (NameObjectEntry)_entriesArray[i];
138-
keys[i] = entry.Key;
139-
values[i] = entry.Value;
140-
}
141-
142-
info.AddValue(KeysName, keys, typeof(String[]));
143-
info.AddValue(ValuesName, values, typeof(Object[]));
144-
info.AddValue(VersionName, _version);
86+
throw new PlatformNotSupportedException();
14587
}
14688

14789
public virtual void OnDeserialization(object sender)
14890
{
149-
if (_keyComparer != null)
150-
{
151-
//Somebody had a dependency on this and fixed us up before the ObjectManager got to it.
152-
return;
153-
}
154-
155-
if (_serializationInfo == null)
156-
{
157-
throw new SerializationException();
158-
}
159-
160-
SerializationInfo info = _serializationInfo;
161-
_serializationInfo = null;
162-
163-
bool readOnly = false;
164-
int count = 0;
165-
string[] keys = null;
166-
object[] values = null;
167-
IHashCodeProvider hashProvider = null;
168-
IComparer comparer = null;
169-
bool hasVersion = false;
170-
int serializedVersion = 0;
171-
172-
SerializationInfoEnumerator enumerator = info.GetEnumerator();
173-
while (enumerator.MoveNext())
174-
{
175-
switch (enumerator.Name)
176-
{
177-
case ReadOnlyName:
178-
readOnly = info.GetBoolean(ReadOnlyName); ;
179-
break;
180-
case HashCodeProviderName:
181-
hashProvider = (IHashCodeProvider)info.GetValue(HashCodeProviderName, typeof(IHashCodeProvider)); ;
182-
break;
183-
case ComparerName:
184-
comparer = (IComparer)info.GetValue(ComparerName, typeof(IComparer));
185-
break;
186-
case KeyComparerName:
187-
_keyComparer = (IEqualityComparer)info.GetValue(KeyComparerName, typeof(IEqualityComparer));
188-
break;
189-
case CountName:
190-
count = info.GetInt32(CountName);
191-
break;
192-
case KeysName:
193-
keys = (String[])info.GetValue(KeysName, typeof(String[]));
194-
break;
195-
case ValuesName:
196-
values = (Object[])info.GetValue(ValuesName, typeof(Object[]));
197-
break;
198-
case VersionName:
199-
hasVersion = true;
200-
serializedVersion = info.GetInt32(VersionName);
201-
break;
202-
}
203-
}
204-
205-
if (_keyComparer == null)
206-
{
207-
if (comparer == null || hashProvider == null)
208-
{
209-
throw new SerializationException();
210-
}
211-
else
212-
{
213-
// create a new key comparer for V1 Object
214-
_keyComparer = new CompatibleComparer(hashProvider, comparer);
215-
}
216-
}
217-
218-
if (keys == null || values == null)
219-
{
220-
throw new SerializationException();
221-
}
222-
223-
Reset(count);
224-
225-
for (int i = 0; i < count; i++)
226-
{
227-
BaseAdd(keys[i], values[i]);
228-
}
229-
230-
_readOnly = readOnly; // after collection populated
231-
if (hasVersion)
232-
{
233-
_version = serializedVersion;
234-
}
91+
throw new PlatformNotSupportedException();
23592
}
23693

23794
//

src/System.Collections.Specialized/src/System/Collections/Specialized/NameValueCollection.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ namespace System.Collections.Specialized
1717
/// <para>Represents a sorted collection of associated <see cref='System.String' qualify='true'/> keys and <see cref='System.String' qualify='true'/> values that
1818
/// can be accessed either with the hash code of the key or with the index.</para>
1919
/// </devdoc>
20-
[Serializable]
21-
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
2220
public class NameValueCollection : NameObjectCollectionBase
2321
{
2422
private String[] _all; // Do not rename (binary serialization)

0 commit comments

Comments
 (0)