本文整理匯總了C#中Newtonsoft.Json.Serialization.JsonArrayContract.CreateWrapper方法的典型用法代碼示例。如果您正苦於以下問題:C# JsonArrayContract.CreateWrapper方法的具體用法?C# JsonArrayContract.CreateWrapper怎麽用?C# JsonArrayContract.CreateWrapper使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Newtonsoft.Json.Serialization.JsonArrayContract
的用法示例。
在下文中一共展示了JsonArrayContract.CreateWrapper方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreateAndPopulateList
private object CreateAndPopulateList(JsonReader reader, string reference, JsonArrayContract contract)
{
return CollectionUtils.CreateAndPopulateList(contract.CreatedType, (l, isTemporaryListReference) =>
{
if (reference != null && isTemporaryListReference)
throw CreateSerializationException(reader, "Cannot preserve reference to array or readonly list: {0}.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
#if !PocketPC
if (contract.OnSerializing != null && isTemporaryListReference)
throw CreateSerializationException(reader, "Cannot call OnSerializing on an array or readonly list: {0}.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
#endif
if (contract.OnError != null && isTemporaryListReference)
throw CreateSerializationException(reader, "Cannot call OnError on an array or readonly list: {0}.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
PopulateList(contract.CreateWrapper(l), reader, reference, contract);
});
}
示例2: CreateAndPopulateList
private object CreateAndPopulateList(JsonReader reader, string reference, JsonArrayContract contract)
{
return CollectionUtils.CreateAndPopulateList(contract.CreatedType, (l, isTemporaryListReference) =>
{
if (reference != null && isTemporaryListReference)
throw new JsonSerializationException("Cannot preserve reference to array or readonly list: {0}".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
if (contract.OnSerializing != null && isTemporaryListReference)
throw new JsonSerializationException("Cannot call OnSerializing on an array or readonly list: {0}".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
if (contract.OnError != null && isTemporaryListReference)
throw new JsonSerializationException("Cannot call OnError on an array or readonly list: {0}".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
if (!contract.IsMultidimensionalArray)
PopulateList(contract.CreateWrapper(l), reader, reference, contract);
else
PopulateMultidimensionalArray(l, reader, reference, contract);
});
}
示例3: CreateNewList
private IList CreateNewList(JsonReader reader, JsonArrayContract contract, out bool createdFromNonDefaultConstructor)
{
// some types like non-generic IEnumerable can be serialized but not deserialized
if (!contract.CanDeserialize)
throw JsonSerializationException.Create(reader, "Cannot create and populate list type {0}.".FormatWith(CultureInfo.InvariantCulture, contract.CreatedType));
if (contract.IsReadOnlyOrFixedSize)
{
createdFromNonDefaultConstructor = true;
IList list = contract.CreateTemporaryCollection();
if (contract.ShouldCreateWrapper)
list = contract.CreateWrapper(list);
return list;
}
else if (contract.DefaultCreator != null && (!contract.DefaultCreatorNonPublic || Serializer._constructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor))
{
object list = contract.DefaultCreator();
if (contract.ShouldCreateWrapper)
list = contract.CreateWrapper(list);
createdFromNonDefaultConstructor = false;
return (IList)list;
}
else if (contract.ParametrizedConstructor != null)
{
createdFromNonDefaultConstructor = true;
return contract.CreateTemporaryCollection();
}
else
{
throw JsonSerializationException.Create(reader, "Unable to find a constructor to use for type {0}.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
}
}
示例4: CreateNewList
// Token: 0x06000BCD RID: 3021
// RVA: 0x00044C00 File Offset: 0x00042E00
private IList CreateNewList(JsonReader reader, JsonArrayContract contract, out bool createdFromNonDefaultCreator)
{
if (!contract.CanDeserialize)
{
throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Cannot create and populate list type {0}.", CultureInfo.InvariantCulture, contract.CreatedType));
}
if (contract.IsReadOnlyOrFixedSize)
{
createdFromNonDefaultCreator = true;
IList list = contract.CreateTemporaryCollection();
if (contract.ShouldCreateWrapper)
{
list = contract.CreateWrapper(list);
}
return list;
}
if (contract.DefaultCreator != null && (!contract.DefaultCreatorNonPublic || this.Serializer._constructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor))
{
object obj = contract.DefaultCreator();
if (contract.ShouldCreateWrapper)
{
obj = contract.CreateWrapper(obj);
}
createdFromNonDefaultCreator = false;
return (IList)obj;
}
if (contract.HasParametrizedCreator)
{
createdFromNonDefaultCreator = true;
return contract.CreateTemporaryCollection();
}
if (!contract.IsInstantiable)
{
throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Could not create an instance of type {0}. Type is an interface or abstract class and cannot be instantiated.", CultureInfo.InvariantCulture, contract.UnderlyingType));
}
throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Unable to find a constructor to use for type {0}.", CultureInfo.InvariantCulture, contract.UnderlyingType));
}