private object CreateAndPopulateDictionary(JsonReader reader, JsonDictionaryContract contract, string id)
        {
            IWrappedDictionary dictionary = contract.CreateWrapper(contract.DefaultCreator());

            PopulateDictionary(dictionary, reader, contract, id);

            return(dictionary.UnderlyingDictionary);
        }
Esempio n. 2
0
 private object CreateAndPopulateDictionary(JsonReader reader, JsonDictionaryContract contract, string id)
 {
     if (contract.DefaultCreator != null && (!contract.DefaultCreatorNonPublic || base.Serializer.ConstructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor))
     {
         object             dictionary        = contract.DefaultCreator();
         IWrappedDictionary wrappedDictionary = contract.CreateWrapper(dictionary);
         PopulateDictionary(wrappedDictionary, reader, contract, id);
         return(wrappedDictionary.UnderlyingDictionary);
     }
     throw new JsonSerializationException("Unable to find a default constructor to use for type {0}.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
 }
    private object CreateAndPopulateDictionary(JsonReader reader, JsonDictionaryContract contract, string id)
    {
      object dictionary;

      if (contract.DefaultCreator != null &&
        (!contract.DefaultCreatorNonPublic || Serializer.ConstructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor))
        dictionary = contract.DefaultCreator();
      else
        throw CreateSerializationException(reader, "Unable to find a default constructor to use for type {0}.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));

      IWrappedDictionary dictionaryWrapper = contract.CreateWrapper(dictionary);

      PopulateDictionary(dictionaryWrapper, reader, contract, id);

      return dictionaryWrapper.UnderlyingDictionary;
    }
        private IDictionary CreateNewDictionary(JsonReader reader, JsonDictionaryContract contract, out bool createdFromNonDefaultConstructor)
        {
            if (contract.IsReadOnlyOrFixedSize)
              {
            createdFromNonDefaultConstructor = true;
            return contract.CreateTemporaryDictionary();
              }
              else if (contract.DefaultCreator != null && (!contract.DefaultCreatorNonPublic || Serializer._constructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor))
              {
            object dictionary = contract.DefaultCreator();

            if (contract.ShouldCreateWrapper)
              dictionary = contract.CreateWrapper(dictionary);

            createdFromNonDefaultConstructor = false;
            return (IDictionary) dictionary;
              }
              else if (contract.ParametrizedConstructor != null)
              {
            createdFromNonDefaultConstructor = true;
            return contract.CreateTemporaryDictionary();
              }
              else
              {
            throw JsonSerializationException.Create(reader, "Unable to find a default constructor to use for type {0}.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
              }
        }
    public object CreateNewDictionary(JsonReader reader, JsonDictionaryContract contract)
    {
      object dictionary;

      if (contract.DefaultCreator != null &&
        (!contract.DefaultCreatorNonPublic || Serializer.ConstructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor))
        dictionary = contract.DefaultCreator();
      else
        throw JsonSerializationException.Create(reader, "Unable to find a default constructor to use for type {0}.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));

      return dictionary;
    }
        private IDictionary CreateNewDictionary(JsonReader reader, JsonDictionaryContract contract, out bool createdFromNonDefaultCreator)
        {
            if (contract.OverrideCreator != null)
            {
                if (contract.HasParameterizedCreator)
                {
                    createdFromNonDefaultCreator = true;
                    return contract.CreateTemporaryDictionary();
                }
                else
                {
                    createdFromNonDefaultCreator = false;
                    return (IDictionary)contract.OverrideCreator();
                }
            }
            else if (contract.IsReadOnlyOrFixedSize)
            {
                createdFromNonDefaultCreator = true;
                return contract.CreateTemporaryDictionary();
            }
            else if (contract.DefaultCreator != null && (!contract.DefaultCreatorNonPublic || Serializer._constructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor))
            {
                object dictionary = contract.DefaultCreator();

                if (contract.ShouldCreateWrapper)
                {
                    dictionary = contract.CreateWrapper(dictionary);
                }

                createdFromNonDefaultCreator = false;
                return (IDictionary)dictionary;
            }
            else if (contract.HasParameterizedCreatorInternal)
            {
                createdFromNonDefaultCreator = true;
                return contract.CreateTemporaryDictionary();
            }
            else
            {
                if (!contract.IsInstantiable)
                {
                    throw JsonSerializationException.Create(reader, "Could not create an instance of type {0}. Type is an interface or abstract class and cannot be instantiated.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
                }

                throw JsonSerializationException.Create(reader, "Unable to find a default constructor to use for type {0}.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
            }
        }
 public object CreateNewDictionary(JsonReader reader, JsonDictionaryContract contract)
 {
   if (contract.DefaultCreator != null && (!contract.DefaultCreatorNonPublic || this.Serializer.ConstructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor))
     return contract.DefaultCreator();
   else
     throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Unable to find a default constructor to use for type {0}.", (IFormatProvider) CultureInfo.InvariantCulture, (object) contract.UnderlyingType));
 }
    public object CreateNewDictionary(JsonReader reader, JsonDictionaryContract contract, out bool isTemporaryDictionary)
    {
      object dictionary;

      if (contract.DefaultCreator != null && (!contract.DefaultCreatorNonPublic || Serializer.ConstructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor))
      {
        dictionary = contract.DefaultCreator();
        isTemporaryDictionary = false;
      }
      else if (contract.IsReadOnlyDictionary)
      {
        dictionary = contract.CreateTemporaryDictionary();
        isTemporaryDictionary = true;
      }
      else
      {
        throw JsonSerializationException.Create(reader, "Unable to find a default constructor to use for type {0}.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
      }

      return dictionary;
    }
        private object CreateAndPopulateDictionary(JsonReader reader, JsonDictionaryContract contract, string id)
        {
            IWrappedDictionary dictionary = contract.CreateWrapper(contract.DefaultCreator());

              PopulateDictionary(dictionary, reader, contract, id);

              return dictionary.UnderlyingDictionary;
        }