System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson.XmlObjectSerializerWriteContextComplexJson.HandleCollectionAssignedToObject C# (CSharp) Method

HandleCollectionAssignedToObject() private method

private HandleCollectionAssignedToObject ( Type declaredType, DataContract &dataContract, object &obj, bool &verifyKnownType ) : void
declaredType System.Type
dataContract DataContract
obj object
verifyKnownType bool
return void
        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);
            }
        }