public virtual void OnDeserialization(Object sender)
{
if (_buckets != null)
{
// Somebody had a dependency on this hashtable and fixed us up before the ObjectManager got to it.
return;
}
SerializationInfo siInfo;
HashHelpers.SerializationInfoTable.TryGetValue(this, out siInfo);
if (siInfo == null)
{
throw new SerializationException(SR.Serialization_InvalidOnDeser);
}
int hashsize = 0;
IComparer c = null;
#pragma warning disable 618
IHashCodeProvider hcp = null;
#pragma warning restore 618
Object[] serKeys = null;
Object[] serValues = null;
SerializationInfoEnumerator enumerator = siInfo.GetEnumerator();
while (enumerator.MoveNext())
{
switch (enumerator.Name)
{
case LoadFactorName:
_loadFactor = siInfo.GetSingle(LoadFactorName);
break;
case HashSizeName:
hashsize = siInfo.GetInt32(HashSizeName);
break;
case KeyComparerName:
_keycomparer = (IEqualityComparer)siInfo.GetValue(KeyComparerName, typeof(IEqualityComparer));
break;
case ComparerName:
c = (IComparer)siInfo.GetValue(ComparerName, typeof(IComparer));
break;
case HashCodeProviderName:
#pragma warning disable 618
hcp = (IHashCodeProvider)siInfo.GetValue(HashCodeProviderName, typeof(IHashCodeProvider));
#pragma warning restore 618
break;
case KeysName:
serKeys = (Object[])siInfo.GetValue(KeysName, typeof(Object[]));
break;
case ValuesName:
serValues = (Object[])siInfo.GetValue(ValuesName, typeof(Object[]));
break;
}
}
_loadsize = (int)(_loadFactor * hashsize);
// V1 object doesn't has _keycomparer field.
if ((_keycomparer == null) && ((c != null) || (hcp != null)))
{
_keycomparer = new CompatibleComparer(hcp, c);
}
_buckets = new bucket[hashsize];
if (serKeys == null)
{
throw new SerializationException(SR.Serialization_MissingKeys);
}
if (serValues == null)
{
throw new SerializationException(SR.Serialization_MissingValues);
}
if (serKeys.Length != serValues.Length)
{
throw new SerializationException(SR.Serialization_KeyValueDifferentSizes);
}
for (int i = 0; i < serKeys.Length; i++)
{
if (serKeys[i] == null)
{
throw new SerializationException(SR.Serialization_NullKey);
}
Insert(serKeys[i], serValues[i], true);
}
_version = siInfo.GetInt32(VersionName);
HashHelpers.SerializationInfoTable.Remove(this);
}