本文整理汇总了C#中Newtonsoft.Json.Serialization.JsonDictionaryContract.DefaultCreator方法的典型用法代码示例。如果您正苦于以下问题:C# JsonDictionaryContract.DefaultCreator方法的具体用法?C# JsonDictionaryContract.DefaultCreator怎么用?C# JsonDictionaryContract.DefaultCreator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Serialization.JsonDictionaryContract
的用法示例。
在下文中一共展示了JsonDictionaryContract.DefaultCreator方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateNewDictionary
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));
}
}
示例2: CreateAndPopulateDictionary
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;
}
示例3: CreateNewDictionary
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;
}
示例4: CreateNewDictionary
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));
}
}
示例5: CreateNewDictionary
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));
}
示例6: CreateNewDictionary
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;
}
示例7: CreateAndPopulateDictionary
private object CreateAndPopulateDictionary(JsonReader reader, JsonDictionaryContract contract, string id)
{
IWrappedDictionary dictionary = contract.CreateWrapper(contract.DefaultCreator());
PopulateDictionary(dictionary, reader, contract, id);
return dictionary.UnderlyingDictionary;
}