private void HandleCollectionAssignedToObject(Type declaredType, ref DataContract dataContract, ref object obj, ref bool verifyKnownType)
{
if ((declaredType != dataContract.UnderlyingType) && (dataContract is CollectionDataContract))
{
if (verifyKnownType)
{
VerifyType(dataContract, declaredType);
verifyKnownType = false;
}
if (((CollectionDataContract)dataContract).Kind == CollectionKind.Dictionary)
{
// Convert non-generic dictionary to generic dictionary
IDictionary dictionaryObj = obj as IDictionary;
Dictionary<object, object> genericDictionaryObj = new Dictionary<object, object>(dictionaryObj.Count);
// Manual use of IDictionaryEnumerator instead of foreach to avoid DictionaryEntry box allocations.
IDictionaryEnumerator e = dictionaryObj.GetEnumerator();
try
{
while (e.MoveNext())
{
DictionaryEntry entry = e.Entry;
genericDictionaryObj.Add(entry.Key, entry.Value);
}
}
finally
{
(e as IDisposable)?.Dispose();
}
obj = genericDictionaryObj;
}
dataContract = GetDataContract(Globals.TypeOfIEnumerable);
}
}