本文整理汇总了C#中StateObject.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# StateObject.GetType方法的具体用法?C# StateObject.GetType怎么用?C# StateObject.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StateObject
的用法示例。
在下文中一共展示了StateObject.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteJson
/// <summary>
/// Writes the JSON representation of a <see cref="StateObject"/> instance.
/// </summary>
/// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
/// <param name="objectType">The object type.</param>
/// <param name="value">The value to serialize.</param>
/// <param name="serializer">The calling serializer.</param>
public void WriteJson(JsonWriter writer, Type objectType, StateObject value, JsonSerializer serializer)
{
var state = value.GetState();
var instanceType = value.GetType();
writer.WriteStartObject();
// Determine if we must write out the state object type (i.e., $type property) or if we can simply infer the type from the objectType provided.
if (objectType != instanceType)
{
writer.WritePropertyName(TypePropertyName);
serializer.Serialize(writer, instanceType.GetFullNameWithAssembly());
}
// Write out each state object property value.
foreach (var item in state)
{
writer.WritePropertyName(item.Key);
if (item.Value == null)
{
writer.WriteNull();
}
else
{
WriteProperty(writer, value.GetFieldType(item.Key), item.Value, serializer);
}
}
writer.WriteEndObject();
}