protected override JsonConverter ResolveContractConverter(Type objectType) { if (objectType is null) { throw new ArgumentNullException(nameof(objectType)); } var converter = converters.FirstOrDefault(c => c.CanConvert(objectType)); if (converter is not null) { return(converter); } else if (typeof(Exception).IsAssignableFrom(objectType)) { converter = new ExceptionConverter(); } else if (typeof(NameValueCollection).IsAssignableFrom(objectType)) { converter = new NameValueCollectionConverter(); } else if (objectType.IsEnum) { converter = new StringEnumConverter(); } else { converter = base.ResolveContractConverter(objectType); } return(converter); }
/// <summary> /// Creates a <see cref="IDictionary{TKey,TValue}"/> from the specified <paramref name="source"/>. /// </summary> /// <param name="source">A <see cref="NameValueCollection"/> to convert into an <see cref="IDictionary{TKey,TValue}"/> equivalent.</param> /// <returns>A <see cref="IDictionary{TKey,TValue}"/> that is equivalent to the specified <paramref name="source"/>.</returns> public static IDictionary <string, string[]> ToDictionary(this NameValueCollection source) { return(NameValueCollectionConverter.ToDictionary(source)); }
/// <summary> /// Creates a <see cref="NameValueCollection"/> from the specified <paramref name="source"/>. /// </summary> /// <param name="source">An <see cref="IDictionary{TKey,TValue}"/> to convert into an <see cref="NameValueCollection"/> equivalent.</param> /// <returns>A <see cref="NameValueCollection"/> that is equivalent to the specified <paramref name="source"/>.</returns> public static NameValueCollection ToNameValueCollection(this IDictionary <string, string[]> source) { return(NameValueCollectionConverter.FromDictionary(source)); }