-Added support for falling back to IEnumerable<T> constructor on lists

-Added support for falling back to IEnumerable<KeyValuePair<TKey, TValue>> constructor on dictionaries
This commit is contained in:
James Newton-King
2013-03-30 13:57:13 +13:00
parent 57d9cb898d
commit 2bf88ebba0
6 changed files with 207 additions and 94 deletions
@@ -69,6 +69,7 @@ namespace Newtonsoft.Json.Serialization
internal bool ShouldCreateWrapper { get; private set; }
internal bool IsReadOnlyOrFixedSize { get; private set; }
internal ConstructorInfo ParametrizedConstructor { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="JsonDictionaryContract"/> class.
@@ -101,6 +102,9 @@ namespace Newtonsoft.Json.Serialization
ReflectionUtils.GetDictionaryKeyValueTypes(UnderlyingType, out keyType, out valueType);
}
if (keyType != null && valueType != null)
ParametrizedConstructor = CollectionUtils.ResolveEnumableCollectionConstructor(underlyingType, ReflectionUtils.MakeGenericType(typeof(KeyValuePair<,>), keyType, valueType));
ShouldCreateWrapper = !typeof (IDictionary).IsAssignableFrom(underlyingType);
DictionaryKeyType = keyType;