Newtonsoft.Json.Serialization.JsonDictionaryContract.JsonDictionaryContract C# (CSharp) Method

JsonDictionaryContract() public method

Initializes a new instance of the JsonDictionaryContract class.
public JsonDictionaryContract ( Type underlyingType ) : System
underlyingType System.Type The underlying type for the contract.
return System
    public JsonDictionaryContract(Type underlyingType)
      : base(underlyingType)
    {
      Type keyType;
      Type valueType;
      if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(IDictionary<,>), out _genericCollectionDefinitionType))
      {
        keyType = _genericCollectionDefinitionType.GetGenericArguments()[0];
        valueType = _genericCollectionDefinitionType.GetGenericArguments()[1];
      }
      else
      {
        ReflectionUtils.GetDictionaryKeyValueTypes(UnderlyingType, out keyType, out valueType);
      }

      DictionaryKeyType = keyType;
      DictionaryValueType = valueType;

      if (IsTypeGenericDictionaryInterface(UnderlyingType))
      {
        CreatedType = ReflectionUtils.MakeGenericType(typeof(Dictionary<,>), keyType, valueType);
      }
      else
      {
        CreatedType = underlyingType;
      }
    }