本文整理汇总了C#中IWrappedDictionary类的典型用法代码示例。如果您正苦于以下问题:C# IWrappedDictionary类的具体用法?C# IWrappedDictionary怎么用?C# IWrappedDictionary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IWrappedDictionary类属于命名空间,在下文中一共展示了IWrappedDictionary类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: PopulateDictionary
private object PopulateDictionary(IWrappedDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, string id)
{
if (id != null)
Serializer.ReferenceResolver.AddReference(this, id, dictionary.UnderlyingDictionary);
contract.InvokeOnDeserializing(dictionary.UnderlyingDictionary, Serializer.Context);
int initialDepth = reader.Depth;
do
{
switch (reader.TokenType)
{
case JsonToken.PropertyName:
object keyValue = reader.Value;
try
{
if (contract.DictionaryKeyContract == null)
contract.DictionaryKeyContract = GetContractSafe(contract.DictionaryKeyType);
try
{
keyValue = EnsureType(reader, keyValue, CultureInfo.InvariantCulture, contract.DictionaryKeyContract, contract.DictionaryKeyType);
}
catch (Exception ex)
{
throw CreateSerializationException(reader, "Could not convert string '{0}' to dictionary key type '{1}'. Create a TypeConverter to convert from the string to the key type object.".FormatWith(CultureInfo.InvariantCulture, reader.Value, contract.DictionaryKeyType), ex);
}
if (contract.DictionaryValueContract == null)
contract.DictionaryValueContract = GetContractSafe(contract.DictionaryValueType);
JsonConverter dictionaryValueConverter = GetConverter(contract.DictionaryValueContract, null);
if (!ReadForType(reader, contract.DictionaryValueContract, dictionaryValueConverter != null, false))
throw CreateSerializationException(reader, "Unexpected end when deserializing object.");
dictionary[keyValue] = CreateValueNonProperty(reader, contract.DictionaryValueType, contract.DictionaryValueContract, dictionaryValueConverter);
}
catch (Exception ex)
{
if (IsErrorHandled(dictionary, contract, keyValue, reader.Path, ex))
HandleError(reader, initialDepth);
else
throw;
}
break;
case JsonToken.Comment:
break;
case JsonToken.EndObject:
contract.InvokeOnDeserialized(dictionary.UnderlyingDictionary, Serializer.Context);
return dictionary.UnderlyingDictionary;
default:
throw CreateSerializationException(reader, "Unexpected token when deserializing object: " + reader.TokenType);
}
} while (reader.Read());
throw CreateSerializationException(reader, "Unexpected end when deserializing object.");
}
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:60,代码来源:JsonSerializerInternalReader.cs
示例2: SerializeDictionary
private void SerializeDictionary(JsonWriter writer, IWrappedDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContract collectionValueContract)
{
contract.InvokeOnSerializing(values.UnderlyingDictionary, Serializer.Context);
SerializeStack.Add(values.UnderlyingDictionary);
writer.WriteStartObject();
bool isReference = contract.IsReference ?? HasFlag(Serializer.PreserveReferencesHandling, PreserveReferencesHandling.Objects);
if (isReference)
{
writer.WritePropertyName(JsonTypeReflector.IdPropertyName);
writer.WriteValue(Serializer.ReferenceResolver.GetReference(this, values.UnderlyingDictionary));
}
if (ShouldWriteType(TypeNameHandling.Objects, contract, member, collectionValueContract))
{
WriteTypeProperty(writer, values.UnderlyingDictionary.GetType());
}
JsonContract childValuesContract = Serializer.ContractResolver.ResolveContract(contract.DictionaryValueType ?? typeof(object));
int initialDepth = writer.Top;
// Mono Unity 3.0 fix
IDictionary d = values;
//#if !(UNITY_IPHONE || UNITY_IOS)
foreach (DictionaryEntry entry in d)
{
string propertyName = GetPropertyName(entry);
propertyName = (contract.PropertyNameResolver != null)
? contract.PropertyNameResolver(propertyName)
: propertyName;
try
{
object value = entry.Value;
JsonContract valueContract = GetContractSafe(value);
if (ShouldWriteReference(value, null, valueContract))
{
writer.WritePropertyName(propertyName);
WriteReference(writer, value);
}
else
{
if (!CheckForCircularReference(value, null, contract))
continue;
writer.WritePropertyName(propertyName);
SerializeValue(writer, value, valueContract, null, childValuesContract);
}
}
catch (Exception ex)
{
if (IsErrorHandled(values.UnderlyingDictionary, contract, propertyName, ex))
HandleError(writer, initialDepth);
else
throw;
}
}
//#else
// string propertyName;
// d.ForEach(originalEntry =>
// {
// var entry = (DictionaryEntry)originalEntry;
// propertyName = GetPropertyName(entry);
// propertyName = (contract.PropertyNameResolver != null)
// ? contract.PropertyNameResolver(propertyName)
// : propertyName;
// try
// {
// object value = entry.Value;
// JsonContract valueContract = GetContractSafe(value);
// if (ShouldWriteReference(value, null, valueContract))
// {
// writer.WritePropertyName(propertyName);
// WriteReference(writer, value);
// }
// else
// {
// if (!CheckForCircularReference(value, null, contract))
// return;
// writer.WritePropertyName(propertyName);
// SerializeValue(writer, value, valueContract, null, childValuesContract);
// }
// }
// catch (Exception ex)
// {
// if (IsErrorHandled(values.UnderlyingDictionary, contract, propertyName, ex))
// HandleError(writer, initialDepth);
// else
// throw;
// }
//.........这里部分代码省略.........
开发者ID:JungWon2,项目名称:memory_book,代码行数:101,代码来源:JsonSerializerInternalWriter.cs
示例3: SerializeDictionary
private void SerializeDictionary(JsonWriter writer, IWrappedDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
{
contract.InvokeOnSerializing(values.UnderlyingDictionary, Serializer.Context);
_serializeStack.Add(values.UnderlyingDictionary);
WriteObjectStart(writer, values.UnderlyingDictionary, contract, member, collectionContract, containerProperty);
if (contract.ItemContract == null)
contract.ItemContract = Serializer.ContractResolver.ResolveContract(contract.DictionaryValueType ?? typeof(object));
int initialDepth = writer.Top;
// Mono Unity 3.0 fix
IWrappedDictionary d = values;
foreach (DictionaryEntry entry in d)
{
string propertyName = GetPropertyName(entry);
propertyName = (contract.PropertyNameResolver != null)
? contract.PropertyNameResolver(propertyName)
: propertyName;
try
{
object value = entry.Value;
JsonContract valueContract = contract.FinalItemContract ?? GetContractSafe(value);
if (ShouldWriteReference(value, null, valueContract, contract, member))
{
writer.WritePropertyName(propertyName);
WriteReference(writer, value);
}
else
{
if (!CheckForCircularReference(writer, value, null, valueContract, contract, member))
continue;
writer.WritePropertyName(propertyName);
SerializeValue(writer, value, valueContract, null, contract, member);
}
}
catch (Exception ex)
{
if (IsErrorHandled(values.UnderlyingDictionary, contract, propertyName, writer.ContainerPath, ex))
HandleError(writer, initialDepth);
else
throw;
}
}
writer.WriteEndObject();
_serializeStack.RemoveAt(_serializeStack.Count - 1);
contract.InvokeOnSerialized(values.UnderlyingDictionary, Serializer.Context);
}
开发者ID:draptik,项目名称:RepoSync,代码行数:59,代码来源:JsonSerializerInternalWriter.cs
示例4: SerializeDictionary
private void SerializeDictionary(JsonWriter writer, IWrappedDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContract collectionValueContract)
{
contract.InvokeOnSerializing(values.UnderlyingDictionary, Serializer.Context);
SerializeStack.Add(values.UnderlyingDictionary);
writer.WriteStartObject();
bool isReference = contract.IsReference ?? HasFlag(Serializer.PreserveReferencesHandling, PreserveReferencesHandling.Objects);
if (isReference)
{
writer.WritePropertyName(JsonTypeReflector.IdPropertyName);
writer.WriteValue(Serializer.ReferenceResolver.GetReference(values.UnderlyingDictionary));
}
if (ShouldWriteType(TypeNameHandling.Objects, contract, member, collectionValueContract))
{
WriteTypeProperty(writer, values.UnderlyingDictionary.GetType());
}
JsonContract childValuesContract = Serializer.ContractResolver.ResolveContract(contract.DictionaryValueType ?? typeof(object));
int initialDepth = writer.Top;
// Mono Unity 3.0 fix
IDictionary d = values;
foreach (DictionaryEntry entry in d)
{
string propertyName = GetPropertyName(entry);
try
{
object value = entry.Value;
JsonContract valueContract = GetContractSafe(value);
if (ShouldWriteReference(value, null, valueContract))
{
writer.WritePropertyName(propertyName);
WriteReference(writer, value);
}
else
{
if (!CheckForCircularReference(value, null, contract))
continue;
writer.WritePropertyName(propertyName);
SerializeValue(writer, value, valueContract, null, childValuesContract);
}
}
catch (Exception ex)
{
if (IsErrorHandled(values.UnderlyingDictionary, contract, propertyName, ex))
HandleError(writer, initialDepth);
else
throw;
}
}
writer.WriteEndObject();
SerializeStack.RemoveAt(SerializeStack.Count - 1);
contract.InvokeOnSerialized(values.UnderlyingDictionary, Serializer.Context);
}
开发者ID:xantilas,项目名称:ghalager-videobrowser-20120129,代码行数:63,代码来源:JsonSerializerInternalWriter.cs
示例5: PopulateDictionary
private IDictionary PopulateDictionary(IWrappedDictionary dictionary, JsonReader reader)
{
Type dictionaryType = dictionary.UnderlyingDictionary.GetType();
Type dictionaryKeyType = ReflectionUtils.GetDictionaryKeyType(dictionaryType);
Type dictionaryValueType = ReflectionUtils.GetDictionaryValueType(dictionaryType);
while (reader.Read())
{
switch (reader.TokenType)
{
case JsonToken.PropertyName:
object keyValue = EnsureType(reader.Value, dictionaryKeyType);
reader.Read();
dictionary.Add(keyValue, CreateObject(reader, dictionaryValueType, null, null));
break;
case JsonToken.EndObject:
return dictionary;
default:
throw new JsonSerializationException("Unexpected token when deserializing object: " + reader.TokenType);
}
}
throw new JsonSerializationException("Unexpected end when deserializing object.");
}
开发者ID:jabbo,项目名称:Jabbo,代码行数:25,代码来源:JsonSerializer.cs
示例6: PopulateDictionary
private object PopulateDictionary(IWrappedDictionary wrappedDictionary, JsonReader reader, JsonDictionaryContract contract, JsonProperty containerProperty, string id)
{
object dictionary = wrappedDictionary.UnderlyingDictionary;
if (id != null)
AddReference(reader, id, dictionary);
OnDeserializing(reader, contract, dictionary);
int initialDepth = reader.Depth;
if (contract.KeyContract == null)
contract.KeyContract = GetContractSafe(contract.DictionaryKeyType);
if (contract.ItemContract == null)
contract.ItemContract = GetContractSafe(contract.DictionaryValueType);
JsonConverter dictionaryValueConverter = contract.ItemConverter ?? GetConverter(contract.ItemContract, null, contract, containerProperty);
bool finished = false;
do
{
switch (reader.TokenType)
{
case JsonToken.PropertyName:
object keyValue = reader.Value;
try
{
try
{
keyValue = EnsureType(reader, keyValue, CultureInfo.InvariantCulture, contract.KeyContract, contract.DictionaryKeyType);
}
catch (Exception ex)
{
throw JsonSerializationException.Create(reader, "Could not convert string '{0}' to dictionary key type '{1}'. Create a TypeConverter to convert from the string to the key type object.".FormatWith(CultureInfo.InvariantCulture, reader.Value, contract.DictionaryKeyType), ex);
}
if (!ReadForType(reader, contract.ItemContract, dictionaryValueConverter != null))
throw JsonSerializationException.Create(reader, "Unexpected end when deserializing object.");
object itemValue;
if (dictionaryValueConverter != null && dictionaryValueConverter.CanRead)
itemValue = DeserializeConvertable(dictionaryValueConverter, reader, contract.DictionaryValueType, null);
else
itemValue = CreateValueInternal(reader, contract.DictionaryValueType, contract.ItemContract, null, contract, containerProperty, null);
wrappedDictionary[keyValue] = itemValue;
}
catch (Exception ex)
{
if (IsErrorHandled(dictionary, contract, keyValue, reader as IJsonLineInfo, reader.Path, ex))
HandleError(reader, true, initialDepth);
else
throw;
}
break;
case JsonToken.Comment:
break;
case JsonToken.EndObject:
finished = true;
break;
default:
throw JsonSerializationException.Create(reader, "Unexpected token when deserializing object: " + reader.TokenType);
}
} while (!finished && reader.Read());
if (!finished)
ThrowUnexpectedEndException(reader, contract, dictionary, "Unexpected end when deserializing object.");
OnDeserialized(reader, contract, dictionary);
return dictionary;
}
开发者ID:joshholl,项目名称:Newtonsoft.Json,代码行数:72,代码来源:JsonSerializerInternalReader.cs
示例7: PopulateDictionary
private object PopulateDictionary(IWrappedDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, string id)
{
if (id != null)
Serializer.ReferenceResolver.AddReference(id, dictionary.UnderlyingDictionary);
contract.InvokeOnDeserializing(dictionary.UnderlyingDictionary, Serializer.Context);
int initialDepth = reader.Depth;
do
{
switch (reader.TokenType)
{
case JsonToken.PropertyName:
object keyValue = EnsureType(reader.Value, contract.DictionaryKeyType);
CheckedRead(reader);
try
{
dictionary[keyValue] = CreateValue(reader, contract.DictionaryValueType, GetContractSafe(contract.DictionaryValueType), null, null);
}
catch (Exception ex)
{
if (IsErrorHandled(dictionary, contract, keyValue, ex))
HandleError(reader, initialDepth);
else
throw;
}
break;
case JsonToken.EndObject:
contract.InvokeOnDeserialized(dictionary.UnderlyingDictionary, Serializer.Context);
return dictionary.UnderlyingDictionary;
default:
throw new JsonSerializationException("Unexpected token when deserializing object: " + reader.TokenType);
}
} while (reader.Read());
throw new JsonSerializationException("Unexpected end when deserializing object.");
}
开发者ID:AndyStewart,项目名称:docsharp,代码行数:40,代码来源:JsonSerializerInternalReader.cs
示例8: PopulateDictionary
private object PopulateDictionary(IWrappedDictionary wrappedDictionary, JsonReader reader, JsonDictionaryContract contract, JsonProperty containerProperty, string id)
{
object underlyingDictionary = wrappedDictionary.UnderlyingDictionary;
if (id != null)
this.AddReference(reader, id, underlyingDictionary);
contract.InvokeOnDeserializing(underlyingDictionary, this.Serializer.Context);
int depth = reader.Depth;
if (contract.KeyContract == null)
contract.KeyContract = this.GetContractSafe(contract.DictionaryKeyType);
if (contract.ItemContract == null)
contract.ItemContract = this.GetContractSafe(contract.DictionaryValueType);
JsonConverter jsonConverter = contract.ItemConverter ?? this.GetConverter(contract.ItemContract, (JsonConverter) null, (JsonContainerContract) contract, containerProperty);
bool flag = false;
do
{
switch (reader.TokenType)
{
case JsonToken.PropertyName:
object keyValue = reader.Value;
try
{
try
{
keyValue = this.EnsureType(reader, keyValue, CultureInfo.InvariantCulture, contract.KeyContract, contract.DictionaryKeyType);
}
catch (Exception ex)
{
throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Could not convert string '{0}' to dictionary key type '{1}'. Create a TypeConverter to convert from the string to the key type object.", (IFormatProvider) CultureInfo.InvariantCulture, reader.Value, (object) contract.DictionaryKeyType), ex);
}
if (!this.ReadForType(reader, contract.ItemContract, jsonConverter != null))
throw JsonSerializationException.Create(reader, "Unexpected end when deserializing object.");
object obj = jsonConverter == null || !jsonConverter.CanRead ? this.CreateValueInternal(reader, contract.DictionaryValueType, contract.ItemContract, (JsonProperty) null, (JsonContainerContract) contract, containerProperty, (object) null) : jsonConverter.ReadJson(reader, contract.DictionaryValueType, (object) null, (JsonSerializer) this.GetInternalSerializer());
wrappedDictionary[keyValue] = obj;
goto case JsonToken.Comment;
}
catch (Exception ex)
{
if (this.IsErrorHandled(underlyingDictionary, (JsonContract) contract, keyValue, reader.Path, ex))
{
this.HandleError(reader, true, depth);
goto case JsonToken.Comment;
}
else
throw;
}
case JsonToken.Comment:
continue;
case JsonToken.EndObject:
flag = true;
goto case JsonToken.Comment;
default:
throw JsonSerializationException.Create(reader, "Unexpected token when deserializing object: " + (object) reader.TokenType);
}
}
while (!flag && reader.Read());
if (!flag)
this.ThrowUnexpectedEndException(reader, (JsonContract) contract, underlyingDictionary, "Unexpected end when deserializing object.");
contract.InvokeOnDeserialized(underlyingDictionary, this.Serializer.Context);
return underlyingDictionary;
}
开发者ID:Zeludon,项目名称:FEZ,代码行数:60,代码来源:JsonSerializerInternalReader.cs
示例9: PopulateDictionary
private IDictionary PopulateDictionary(IWrappedDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, string id)
{
if (id != null)
_serializer.ReferenceResolver.AddReference(id, dictionary.UnderlyingDictionary);
contract.InvokeOnDeserializing(dictionary.UnderlyingDictionary);
do
{
switch (reader.TokenType)
{
case JsonToken.PropertyName:
object keyValue = EnsureType(reader.Value, contract.DictionaryKeyType);
CheckedRead(reader);
dictionary.Add(keyValue, CreateValue(reader, contract.DictionaryValueType, null, null));
break;
case JsonToken.EndObject:
contract.InvokeOnDeserialized(dictionary.UnderlyingDictionary);
return dictionary;
default:
throw new JsonSerializationException("Unexpected token when deserializing object: " + reader.TokenType);
}
} while (reader.Read());
throw new JsonSerializationException("Unexpected end when deserializing object.");
}
开发者ID:BGCX262,项目名称:zulu-omoto-pos-client-svn-to-git,代码行数:28,代码来源:JsonSerializerReader.cs
示例10: SerializeDictionary
private void SerializeDictionary(JsonWriter writer, IWrappedDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
{
contract.InvokeOnSerializing(values.UnderlyingDictionary, this.Serializer.Context);
this._serializeStack.Add(values.UnderlyingDictionary);
this.WriteObjectStart(writer, values.UnderlyingDictionary, (JsonContract) contract, member, collectionContract, containerProperty);
if (contract.ItemContract == null)
contract.ItemContract = this.Serializer.ContractResolver.ResolveContract(contract.DictionaryValueType ?? typeof (object));
int top = writer.Top;
foreach (DictionaryEntry entry in (IDictionary) values)
{
string propertyName = this.GetPropertyName(entry);
string name = contract.PropertyNameResolver != null ? contract.PropertyNameResolver(propertyName) : propertyName;
try
{
object obj = entry.Value;
JsonContract jsonContract = contract.FinalItemContract ?? this.GetContractSafe(obj);
if (this.ShouldWriteReference(obj, (JsonProperty) null, jsonContract, (JsonContainerContract) contract, member))
{
writer.WritePropertyName(name);
this.WriteReference(writer, obj);
}
else if (this.CheckForCircularReference(writer, obj, (JsonProperty) null, jsonContract, (JsonContainerContract) contract, member))
{
writer.WritePropertyName(name);
this.SerializeValue(writer, obj, jsonContract, (JsonProperty) null, (JsonContainerContract) contract, member);
}
}
catch (Exception ex)
{
if (this.IsErrorHandled(values.UnderlyingDictionary, (JsonContract) contract, (object) name, writer.ContainerPath, ex))
this.HandleError(writer, top);
else
throw;
}
}
writer.WriteEndObject();
this._serializeStack.RemoveAt(this._serializeStack.Count - 1);
contract.InvokeOnSerialized(values.UnderlyingDictionary, this.Serializer.Context);
}
开发者ID:Zeludon,项目名称:FEZ,代码行数:39,代码来源:JsonSerializerInternalWriter.cs
注:本文中的IWrappedDictionary类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论