bool INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func <IParser, Type, object> nestedObjectDeserializer, out object value) { bool canUpdate = true; Type implementedGenericInterface = ReflectionUtility.GetImplementedGenericInterface(expectedType, typeof(ICollection <>)); Type tItem; IList list; if (implementedGenericInterface != null) { Type[] genericArguments = implementedGenericInterface.GetGenericArguments(); tItem = genericArguments[0]; value = _objectFactory.Create(expectedType); list = (value as IList); if (list == null) { Type implementedGenericInterface2 = ReflectionUtility.GetImplementedGenericInterface(expectedType, typeof(IList <>)); canUpdate = (implementedGenericInterface2 != null); list = new GenericCollectionToNonGenericAdapter(value, implementedGenericInterface, implementedGenericInterface2); } } else { if (!typeof(IList).IsAssignableFrom(expectedType)) { value = null; return(false); } tItem = typeof(object); value = _objectFactory.Create(expectedType); list = (IList)value; } DeserializeHelper(tItem, parser, nestedObjectDeserializer, list, canUpdate); return(true); }
bool INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func <IParser, Type, object> nestedObjectDeserializer, out object value) { IList list; bool canUpdate = true; Type itemType; var genericCollectionType = ReflectionUtility.GetImplementedGenericInterface(expectedType, typeof(ICollection <>)); if (genericCollectionType != null) { var genericArguments = genericCollectionType.GetGenericArguments(); itemType = genericArguments[0]; value = _objectFactory.Create(expectedType); list = value as IList; if (list == null) { var genericListType = ReflectionUtility.GetImplementedGenericInterface(expectedType, typeof(IList <>)); canUpdate = genericListType != null; list = new GenericCollectionToNonGenericAdapter(value, genericCollectionType, genericListType); } } else if (typeof(IList).IsAssignableFrom(expectedType)) { itemType = typeof(object); value = _objectFactory.Create(expectedType); list = (IList)value; } else { value = null; return(false); } DeserializeHelper(itemType, parser, nestedObjectDeserializer, list, canUpdate); return(true); }