本文整理汇总了C#中IWrappedCollection类的典型用法代码示例。如果您正苦于以下问题:C# IWrappedCollection类的具体用法?C# IWrappedCollection怎么用?C# IWrappedCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IWrappedCollection类属于命名空间,在下文中一共展示了IWrappedCollection类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SerializeList
private void SerializeList(JsonWriter writer, IWrappedCollection values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
{
contract.InvokeOnSerializing(values.UnderlyingCollection, Serializer.Context);
_serializeStack.Add(values.UnderlyingCollection);
bool hasWrittenMetadataObject = WriteStartArray(writer, values.UnderlyingCollection, contract, member, collectionContract, containerProperty);
writer.WriteStartArray();
int initialDepth = writer.Top;
int index = 0;
// note that an error in the IEnumerable won't be caught
foreach (object value in values)
{
try
{
JsonContract valueContract = contract.FinalItemContract ?? GetContractSafe(value);
if (ShouldWriteReference(value, null, valueContract, contract, member))
{
WriteReference(writer, value);
}
else
{
if (CheckForCircularReference(writer, value, null, valueContract, contract, member))
{
SerializeValue(writer, value, valueContract, null, contract, member);
}
}
}
catch (Exception ex)
{
if (IsErrorHandled(values.UnderlyingCollection, contract, index, writer.ContainerPath, ex))
HandleError(writer, initialDepth);
else
throw;
}
finally
{
index++;
}
}
writer.WriteEndArray();
if (hasWrittenMetadataObject)
writer.WriteEndObject();
_serializeStack.RemoveAt(_serializeStack.Count - 1);
contract.InvokeOnSerialized(values.UnderlyingCollection, Serializer.Context);
}
开发者ID:draptik,项目名称:RepoSync,代码行数:54,代码来源:JsonSerializerInternalWriter.cs
示例2: 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.");
}
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:63,代码来源:JsonSerializerInternalReader.cs
示例3: SerializeList
private void SerializeList(JsonWriter writer, IWrappedCollection values, JsonArrayContract contract, JsonProperty member, JsonContract collectionValueContract)
{
contract.InvokeOnSerializing(values.UnderlyingCollection, Serializer.Context);
SerializeStack.Add(values.UnderlyingCollection);
bool isReference = contract.IsReference ?? HasFlag(Serializer.PreserveReferencesHandling, PreserveReferencesHandling.Arrays);
bool includeTypeDetails = ShouldWriteType(TypeNameHandling.Arrays, contract, member, collectionValueContract);
if (isReference || includeTypeDetails)
{
writer.WriteStartObject();
if (isReference)
{
writer.WritePropertyName(JsonTypeReflector.IdPropertyName);
writer.WriteValue(Serializer.ReferenceResolver.GetReference(this, values.UnderlyingCollection));
}
if (includeTypeDetails)
{
WriteTypeProperty(writer, values.UnderlyingCollection.GetType());
}
writer.WritePropertyName(JsonTypeReflector.ArrayValuesPropertyName);
}
JsonContract childValuesContract = Serializer.ContractResolver.ResolveContract(contract.CollectionItemType ?? typeof(object));
writer.WriteStartArray();
int initialDepth = writer.Top;
int index = 0;
// note that an error in the IEnumerable won't be caught
#if !(UNITY_IPHONE || UNITY_IOS)
foreach (object value in values)
{
try
{
JsonContract valueContract = GetContractSafe(value);
if (ShouldWriteReference(value, null, valueContract))
{
WriteReference(writer, value);
}
else
{
if (CheckForCircularReference(value, null, contract))
{
SerializeValue(writer, value, valueContract, null, childValuesContract);
}
}
}
catch (Exception ex)
{
if (IsErrorHandled(values.UnderlyingCollection, contract, index, ex))
HandleError(writer, initialDepth);
else
throw;
}
finally
{
index++;
}
}
#else
values.ForEach(value =>
{
try
{
JsonContract valueContract = GetContractSafe(value);
if (ShouldWriteReference(value, null, valueContract))
{
WriteReference(writer, value);
}
else
{
if (CheckForCircularReference(value, null, contract))
{
SerializeValue(writer, value, valueContract, null, childValuesContract);
}
}
}
catch (Exception ex)
{
if (IsErrorHandled(values.UnderlyingCollection, contract, index, ex))
HandleError(writer, initialDepth);
else
throw;
}
finally
{
index++;
}
});
#endif
//.........这里部分代码省略.........
开发者ID:JungWon2,项目名称:memory_book,代码行数:101,代码来源:JsonSerializerInternalWriter.cs
示例4: 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.");
}
开发者ID:nathanpalmer,项目名称:ravendb,代码行数:41,代码来源:JsonSerializerInternalReader.cs
示例5: WriteStartArray
private bool WriteStartArray(JsonWriter writer, IWrappedCollection values, JsonArrayContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
{
bool isReference = ResolveIsReference(contract, member, containerContract, containerProperty) ?? HasFlag(Serializer.PreserveReferencesHandling, PreserveReferencesHandling.Arrays);
bool includeTypeDetails = ShouldWriteType(TypeNameHandling.Arrays, contract, member, containerContract, containerProperty);
bool writeMetadataObject = isReference || includeTypeDetails;
if (writeMetadataObject)
{
writer.WriteStartObject();
if (isReference)
{
writer.WritePropertyName(JsonTypeReflector.IdPropertyName);
writer.WriteValue(Serializer.ReferenceResolver.GetReference(this, values.UnderlyingCollection));
}
if (includeTypeDetails)
{
WriteTypeProperty(writer, values.UnderlyingCollection.GetType());
}
writer.WritePropertyName(JsonTypeReflector.ArrayValuesPropertyName);
}
if (contract.ItemContract == null)
contract.ItemContract = Serializer.ContractResolver.ResolveContract(contract.CollectionItemType ?? typeof (object));
return writeMetadataObject;
}
开发者ID:taliesins,项目名称:Newtonsoft.Json,代码行数:27,代码来源:JsonSerializerInternalWriter.cs
示例6: 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;
}
开发者ID:joshholl,项目名称:Newtonsoft.Json,代码行数:86,代码来源:JsonSerializerInternalReader.cs
示例7: 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;
}
}
开发者ID:Zeludon,项目名称:FEZ,代码行数:66,代码来源:JsonSerializerInternalReader.cs
示例8: SerializeList
private void SerializeList(JsonWriter writer, IWrappedCollection values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) {
OnSerializing(writer, contract, values.UnderlyingCollection);
_serializeStack.Add(values.UnderlyingCollection);
bool hasWrittenMetadataObject = WriteStartArray(writer, values.UnderlyingCollection, contract, member, collectionContract, containerProperty);
writer.WriteStartArray();
int initialDepth = writer.Top;
int index = 0;
object valuePrevious = new object();
try {
// note that an error in the IEnumerable won't be caught
foreach (object value in values) {
try {
JsonContract valueContract = contract.FinalItemContract ?? GetContractSafe(value);
if (ShouldWriteReference(value, null, valueContract, contract, member)) {
WriteReference(writer, value);
} else {
if (CheckForCircularReference(writer, value, null, valueContract, contract, member)) {
SerializeValue(writer, value, valueContract, null, contract, member);
}
}
} catch (Exception ex) {
if (IsErrorHandled(values.UnderlyingCollection, contract, index, null, writer.ContainerPath, ex))
HandleError(writer, initialDepth);
else
throw;
} finally {
index++;
valuePrevious = value;
}
}
} catch (Exception e) {
string msg = "valuePrevious[" + valuePrevious.ToString() + "] trying to catch COLLECTION_CHANGED";
throw new Exception(msg, e);
}
writer.WriteEndArray();
if (hasWrittenMetadataObject)
writer.WriteEndObject();
_serializeStack.RemoveAt(_serializeStack.Count - 1);
OnSerialized(writer, contract, values.UnderlyingCollection);
}
开发者ID:sanyaade-fintechnology,项目名称:SquareOne,代码行数:50,代码来源:JsonSerializerInternalWriter.cs
示例9: 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.");
}
开发者ID:GeorgeR,项目名称:Newtonsoft.Json,代码行数:82,代码来源:JsonSerializerInternalReader.cs
示例10: SerializeList
private void SerializeList(JsonWriter writer, IWrappedCollection values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
{
contract.InvokeOnSerializing(values.UnderlyingCollection, this.Serializer.Context);
this._serializeStack.Add(values.UnderlyingCollection);
bool flag = this.WriteStartArray(writer, values.UnderlyingCollection, contract, member, collectionContract, containerProperty);
writer.WriteStartArray();
int top = writer.Top;
int num = 0;
foreach (object obj in (IEnumerable) values)
{
try
{
JsonContract jsonContract = contract.FinalItemContract ?? this.GetContractSafe(obj);
if (this.ShouldWriteReference(obj, (JsonProperty) null, jsonContract, (JsonContainerContract) contract, member))
this.WriteReference(writer, obj);
else if (this.CheckForCircularReference(writer, obj, (JsonProperty) null, jsonContract, (JsonContainerContract) contract, member))
this.SerializeValue(writer, obj, jsonContract, (JsonProperty) null, (JsonContainerContract) contract, member);
}
catch (Exception ex)
{
if (this.IsErrorHandled(values.UnderlyingCollection, (JsonContract) contract, (object) num, writer.ContainerPath, ex))
this.HandleError(writer, top);
else
throw;
}
finally
{
++num;
}
}
writer.WriteEndArray();
if (flag)
writer.WriteEndObject();
this._serializeStack.RemoveAt(this._serializeStack.Count - 1);
contract.InvokeOnSerialized(values.UnderlyingCollection, this.Serializer.Context);
}
开发者ID:Zeludon,项目名称:FEZ,代码行数:36,代码来源:JsonSerializerInternalWriter.cs
示例11: SerializeList
private void SerializeList(JsonWriter writer, IWrappedCollection values, JsonArrayContract contract, JsonProperty member, JsonContract collectionValueContract)
{
contract.InvokeOnSerializing(values.UnderlyingCollection, Serializer.Context);
SerializeStack.Add(values.UnderlyingCollection);
bool isReference = contract.IsReference ?? HasFlag(Serializer.PreserveReferencesHandling, PreserveReferencesHandling.Arrays);
bool includeTypeDetails = ShouldWriteType(TypeNameHandling.Arrays, contract, member, collectionValueContract);
if (isReference || includeTypeDetails)
{
writer.WriteStartObject();
if (isReference)
{
writer.WritePropertyName(JsonTypeReflector.IdPropertyName);
writer.WriteValue(Serializer.ReferenceResolver.GetReference(this, values.UnderlyingCollection));
}
if (includeTypeDetails)
{
WriteTypeProperty(writer, values.UnderlyingCollection.GetType());
}
writer.WritePropertyName(JsonTypeReflector.ArrayValuesPropertyName);
}
JsonContract childValuesContract = Serializer.ContractResolver.ResolveContract(contract.CollectionItemType ?? typeof(object));
writer.WriteStartArray();
int initialDepth = writer.Top;
int index = 0;
// note that an error in the IEnumerable won't be caught
foreach (object value in values)
{
try
{
// Note: So apparently the type of the items in the list are being retrieved already in the childValuesContract. Check to see
// if the type here is correct, and check to see if the contract retrieved here is the same as the childValuesContract.
JsonContract valueContract = childValuesContract;
if(value != null)
valueContract = Serializer.ContractResolver.ResolveContract(value.GetType());
//JsonContract valueContract = GetContractSafe(value);
if (ShouldWriteReference(value, null, valueContract))
{
WriteReference(writer, value);
}
else
{
if (CheckForCircularReference(value, null, contract))
{
SerializeValue(writer, value, valueContract, null, childValuesContract);
}
}
}
catch (Exception ex)
{
if (IsErrorHandled(values.UnderlyingCollection, contract, index, ex))
HandleError(writer, initialDepth);
else
throw;
}
finally
{
index++;
}
}
writer.WriteEndArray();
if (isReference || includeTypeDetails)
{
writer.WriteEndObject();
}
SerializeStack.RemoveAt(SerializeStack.Count - 1);
contract.InvokeOnSerialized(values.UnderlyingCollection, Serializer.Context);
}
开发者ID:TSASoftware,项目名称:Json.Net,代码行数:83,代码来源:JsonSerializerInternalWriter.cs
注:本文中的IWrappedCollection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论