本文整理汇总了C#中IWrappedCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# IWrappedCollection.Add方法的具体用法?C# IWrappedCollection.Add怎么用?C# IWrappedCollection.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWrappedCollection
的用法示例。
在下文中一共展示了IWrappedCollection.Add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PopulateList
private object PopulateList(IWrappedCollection wrappedList, JsonReader reader, string reference, JsonArrayContract contract)
{
object list = wrappedList.UnderlyingCollection;
// can't populate an existing array
if (wrappedList.IsFixedSize)
{
reader.Skip();
return wrappedList.UnderlyingCollection;
}
if (reference != null)
Serializer.ReferenceResolver.AddReference(this, reference, list);
contract.InvokeOnDeserializing(list, Serializer.Context);
int initialDepth = reader.Depth;
int index = 0;
JsonContract collectionItemContract = GetContractSafe(contract.CollectionItemType);
JsonConverter collectionItemConverter = GetConverter(collectionItemContract, null);
while (true)
{
try
{
if (ReadForType(reader, collectionItemContract, collectionItemConverter != null, true))
{
switch (reader.TokenType)
{
case JsonToken.EndArray:
contract.InvokeOnDeserialized(list, Serializer.Context);
return wrappedList.UnderlyingCollection;
case JsonToken.Comment:
break;
default:
object value = CreateValueNonProperty(reader, contract.CollectionItemType, collectionItemContract, collectionItemConverter);
wrappedList.Add(value);
break;
}
}
else
{
break;
}
}
catch (Exception ex)
{
if (IsErrorHandled(list, contract, index, reader.Path, ex))
HandleError(reader, initialDepth);
else
throw;
}
finally
{
index++;
}
}
throw CreateSerializationException(reader, "Unexpected end when deserializing array.");
}
示例2: PopulateList
private object PopulateList(IWrappedCollection wrappedList, JsonReader reader, string reference, JsonArrayContract contract)
{
object list = wrappedList.UnderlyingCollection;
if (reference != null)
Serializer.ReferenceResolver.AddReference(reference, list);
contract.InvokeOnDeserializing(list, Serializer.Context);
int initialDepth = reader.Depth;
while (reader.Read())
{
switch (reader.TokenType)
{
case JsonToken.EndArray:
contract.InvokeOnDeserialized(list, Serializer.Context);
return wrappedList.UnderlyingCollection;
case JsonToken.Comment:
break;
default:
try
{
object value = CreateValueNonProperty(reader, contract.CollectionItemType, GetContractSafe(contract.CollectionItemType));
wrappedList.Add(value);
}
catch (Exception ex)
{
if (IsErrorHandled(list, contract, wrappedList.Count, ex))
HandleError(reader, initialDepth);
else
throw;
}
break;
}
}
throw new JsonSerializationException("Unexpected end when deserializing array.");
}
示例3: PopulateList
private object PopulateList(IWrappedCollection wrappedList, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, string id)
{
object underlyingCollection = wrappedList.UnderlyingCollection;
if (id != null)
this.AddReference(reader, id, underlyingCollection);
if (wrappedList.IsFixedSize)
{
reader.Skip();
return underlyingCollection;
}
else
{
contract.InvokeOnDeserializing(underlyingCollection, this.Serializer.Context);
int depth = reader.Depth;
JsonContract contractSafe = this.GetContractSafe(contract.CollectionItemType);
JsonConverter converter = this.GetConverter(contractSafe, (JsonConverter) null, (JsonContainerContract) contract, containerProperty);
int? nullable1 = new int?();
bool flag = false;
do
{
try
{
if (this.ReadForType(reader, contractSafe, converter != null))
{
switch (reader.TokenType)
{
case JsonToken.Comment:
break;
case JsonToken.EndArray:
flag = true;
break;
default:
object obj = converter == null || !converter.CanRead ? this.CreateValueInternal(reader, contract.CollectionItemType, contractSafe, (JsonProperty) null, (JsonContainerContract) contract, containerProperty, (object) null) : converter.ReadJson(reader, contract.CollectionItemType, (object) null, (JsonSerializer) this.GetInternalSerializer());
wrappedList.Add(obj);
break;
}
}
else
break;
}
catch (Exception ex)
{
JsonPosition position = reader.GetPosition(depth);
if (this.IsErrorHandled(underlyingCollection, (JsonContract) contract, (object) position.Position, reader.Path, ex))
{
this.HandleError(reader, true, depth);
if (nullable1.HasValue)
{
int? nullable2 = nullable1;
int? nullable3 = position.Position;
if ((nullable2.GetValueOrDefault() != nullable3.GetValueOrDefault() ? 0 : (nullable2.HasValue == nullable3.HasValue ? 1 : 0)) != 0)
throw JsonSerializationException.Create(reader, "Infinite loop detected from error handling.", ex);
}
nullable1 = position.Position;
}
else
throw;
}
}
while (!flag);
if (!flag)
this.ThrowUnexpectedEndException(reader, (JsonContract) contract, underlyingCollection, "Unexpected end when deserializing array.");
contract.InvokeOnDeserialized(underlyingCollection, this.Serializer.Context);
return underlyingCollection;
}
}
示例4: PopulateList
private object PopulateList(IWrappedCollection wrappedList, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, string id)
{
object list = wrappedList.UnderlyingCollection;
if (id != null)
AddReference(reader, id, list);
// can't populate an existing array
if (wrappedList.IsFixedSize)
{
reader.Skip();
return list;
}
OnDeserializing(reader, contract, list);
int initialDepth = reader.Depth;
JsonContract collectionItemContract = GetContractSafe(contract.CollectionItemType);
JsonConverter collectionItemConverter = GetConverter(collectionItemContract, null, contract, containerProperty);
int? previousErrorIndex = null;
bool finished = false;
do
{
try
{
if (ReadForType(reader, collectionItemContract, collectionItemConverter != null))
{
switch (reader.TokenType)
{
case JsonToken.EndArray:
finished = true;
break;
case JsonToken.Comment:
break;
default:
object value;
if (collectionItemConverter != null && collectionItemConverter.CanRead)
value = DeserializeConvertable(collectionItemConverter, reader, contract.CollectionItemType, null);
else
value = CreateValueInternal(reader, contract.CollectionItemType, collectionItemContract, null, contract, containerProperty, null);
wrappedList.Add(value);
break;
}
}
else
{
break;
}
}
catch (Exception ex)
{
JsonPosition errorPosition = reader.GetPosition(initialDepth);
if (IsErrorHandled(list, contract, errorPosition.Position, reader as IJsonLineInfo, reader.Path, ex))
{
HandleError(reader, true, initialDepth);
if (previousErrorIndex != null && previousErrorIndex == errorPosition.Position)
{
// reader index has not moved since previous error handling
// break out of reading array to prevent infinite loop
throw JsonSerializationException.Create(reader, "Infinite loop detected from error handling.", ex);
}
else
{
previousErrorIndex = errorPosition.Position;
}
}
else
{
throw;
}
}
} while (!finished);
if (!finished)
ThrowUnexpectedEndException(reader, contract, list, "Unexpected end when deserializing array.");
OnDeserialized(reader, contract, list);
return list;
}
示例5: PopulateList
private object PopulateList(IWrappedCollection wrappedList, JsonReader reader, string reference, JsonArrayContract contract, JsonProperty containerProperty)
{
object list = wrappedList.UnderlyingCollection;
// can't populate an existing array
if (wrappedList.IsFixedSize)
{
reader.Skip();
return wrappedList.UnderlyingCollection;
}
if (reference != null)
Serializer.ReferenceResolver.AddReference(this, reference, list);
contract.InvokeOnDeserializing(list, Serializer.Context);
int initialDepth = reader.Depth;
JsonContract collectionItemContract = GetContractSafe(contract.CollectionItemType);
JsonConverter collectionItemConverter = GetConverter(collectionItemContract, null, contract, containerProperty);
int? previousErrorIndex = null;
while (true)
{
try
{
if (ReadForType(reader, collectionItemContract, collectionItemConverter != null, true))
{
switch (reader.TokenType)
{
case JsonToken.EndArray:
contract.InvokeOnDeserialized(list, Serializer.Context);
return wrappedList.UnderlyingCollection;
case JsonToken.Comment:
break;
default:
object value;
if (collectionItemConverter != null && collectionItemConverter.CanRead)
value = collectionItemConverter.ReadJson(reader, contract.CollectionItemType, null, GetInternalSerializer());
else
value = CreateValueInternal(reader, contract.CollectionItemType, collectionItemContract, null, contract, containerProperty, null);
wrappedList.Add(value);
break;
}
}
else
{
break;
}
}
catch (Exception ex)
{
JsonPosition errorPosition = reader.GetPosition(initialDepth);
if (IsErrorHandled(list, contract, errorPosition.Position, reader.Path, ex))
{
HandleError(reader, true, initialDepth);
if (previousErrorIndex != null && previousErrorIndex == errorPosition.Position)
{
// reader index has not moved since previous error handling
// break out of reading array to prevent infinite loop
throw JsonSerializationException.Create(reader, "Infinite loop detected from error handling.", ex);
}
else
{
previousErrorIndex = errorPosition.Position;
}
}
else
{
throw;
}
}
}
throw JsonSerializationException.Create(reader, "Unexpected end when deserializing array.");
}