bool INodeDeserializer.Deserialize(EventReader reader, Type expectedType, Func<EventReader, Type, object> nestedObjectDeserializer, out object value) { IDictionary dictionary; Type keyType, valueType; var genericDictionaryType = ReflectionUtility.GetImplementedGenericInterface(expectedType, typeof(IDictionary<,>)); if (genericDictionaryType != null) { var genericArguments = genericDictionaryType.GetGenericArguments(); keyType = genericArguments[0]; valueType = genericArguments[1]; value = _objectFactory.Create(expectedType); dictionary = value as IDictionary; if (dictionary == null) { dictionary = new GenericDictionaryToNonGenericAdapter(value, genericDictionaryType); } } else if (typeof(IDictionary).IsAssignableFrom(expectedType)) { keyType = typeof(object); valueType = typeof(object); value = _objectFactory.Create(expectedType); dictionary = (IDictionary)value; } else { value = null; return false; } DeserializeHelper(keyType, valueType, reader, expectedType, nestedObjectDeserializer, dictionary); return true; }
protected virtual void TraverseObject(IObjectDescriptor value, IObjectGraphVisitor visitor, int currentDepth) { if (typeof(IDictionary).IsAssignableFrom(value.Type)) { TraverseDictionary(value, visitor, currentDepth, typeof(object), typeof(object)); return; } var genericDictionaryType = ReflectionUtility.GetImplementedGenericInterface(value.Type, typeof(IDictionary<,>)); if (genericDictionaryType != null) { var adaptedDictionary = new GenericDictionaryToNonGenericAdapter(value.Value, genericDictionaryType); var genericArguments = genericDictionaryType.GetGenericArguments(); TraverseDictionary(new ObjectDescriptor(adaptedDictionary, value.Type, value.StaticType, value.ScalarStyle), visitor, currentDepth, genericArguments[0], genericArguments[1]); return; } if (typeof(IEnumerable).IsAssignableFrom(value.Type)) { TraverseList(value, visitor, currentDepth); return; } TraverseProperties(value, visitor, currentDepth); }