本文整理汇总了C#中Newtonsoft.Json.Serialization.JsonDictionaryContract.InvokeOnSerializing方法的典型用法代码示例。如果您正苦于以下问题:C# JsonDictionaryContract.InvokeOnSerializing方法的具体用法?C# JsonDictionaryContract.InvokeOnSerializing怎么用?C# JsonDictionaryContract.InvokeOnSerializing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Serialization.JsonDictionaryContract
的用法示例。
在下文中一共展示了JsonDictionaryContract.InvokeOnSerializing方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例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;
// }
//.........这里部分代码省略.........
示例3: 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);
}
示例4: SerializeDictionary
private void SerializeDictionary(JsonWriter writer, IDictionary values, JsonDictionaryContract contract)
{
contract.InvokeOnSerializing(values);
SerializeStack.Add(values);
writer.WriteStartObject();
bool isReference = contract.IsReference ?? HasFlag(_serializer.PreserveReferencesHandling, PreserveReferencesHandling.Objects);
if (isReference)
{
writer.WritePropertyName(JsonTypeReflector.IdPropertyName);
writer.WriteValue(_serializer.ReferenceResolver.GetReference(values));
}
if (HasFlag(_serializer.TypeNameHandling, TypeNameHandling.Objects))
{
WriteTypeProperty(writer, values.GetType());
}
foreach (DictionaryEntry entry in values)
{
string propertyName = entry.Key.ToString();
object value = entry.Value;
if (ShouldWriteReference(value, null))
{
writer.WritePropertyName(propertyName);
WriteReference(writer, value);
}
else
{
if (!CheckForCircularReference(value, null))
continue;
writer.WritePropertyName(propertyName);
SerializeValue(writer, value, null);
}
}
writer.WriteEndObject();
SerializeStack.RemoveAt(SerializeStack.Count - 1);
contract.InvokeOnSerialized(values);
}
示例5: SerializeDictionary
private void SerializeDictionary(JsonWriter writer, IDictionary values, JsonDictionaryContract contract)
{
contract.InvokeOnSerializing(values);
SerializeStack.Add(values);
writer.WriteStartObject();
bool isReference = contract.IsReference ?? HasFlag(Serializer.PreserveReferencesHandling, PreserveReferencesHandling.Objects);
if (isReference)
{
writer.WritePropertyName(JsonTypeReflector.IdPropertyName);
writer.WriteValue(Serializer.ReferenceResolver.GetReference(values));
}
if (HasFlag(Serializer.TypeNameHandling, TypeNameHandling.Objects))
{
WriteTypeProperty(writer, values.GetType());
}
int initialDepth = writer.Top;
foreach (DictionaryEntry entry in values)
{
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))
continue;
writer.WritePropertyName(propertyName);
SerializeValue(writer, value, null, valueContract);
}
}
catch (Exception ex)
{
if (IsErrorHandled(values, contract, propertyName, ex))
HandleError(writer, initialDepth);
else
throw;
}
}
writer.WriteEndObject();
SerializeStack.RemoveAt(SerializeStack.Count - 1);
contract.InvokeOnSerialized(values);
}
示例6: 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);
}