本文整理汇总了C#中IJsonSerializer.SerializeValue方法的典型用法代码示例。如果您正苦于以下问题:C# IJsonSerializer.SerializeValue方法的具体用法?C# IJsonSerializer.SerializeValue怎么用?C# IJsonSerializer.SerializeValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IJsonSerializer
的用法示例。
在下文中一共展示了IJsonSerializer.SerializeValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeMembers
/// <summary>
/// Serialize a list of members from the object.
/// </summary>
/// <param name="serializer">The serializer to utilize when serializing the values.</param>
/// <param name="type">The type of the object to serialize the members from.</param>
/// <param name="value">The value to serialize the members from.</param>
/// <returns>The list of members that make up the object.</returns>
static IEnumerable<JsonMember> SerializeMembers(IJsonSerializer serializer, Type type, object value)
{
foreach (var property in type.GetRuntimeProperties().Where(p => p.CanRead))
{
yield return new JsonMember(serializer.FieldNamingStrategy.GetName(property.Name), serializer.SerializeValue(property.GetValue(value)));
}
}
示例2: SerializeValue
/// <summary>
/// Serialize the value.
/// </summary>
/// <param name="serializer">The serializer to utilize when serializing nested objects.</param>
/// <param name="type">The CLR type of the value to serialize.</param>
/// <param name="value">The value to serialize.</param>
/// <returns>The JSON value that represents the given CLR value.</returns>
public JsonValue SerializeValue(IJsonSerializer serializer, Type type, object value)
{
return serializer.SerializeValue(value);
}
示例3: SerializeValue
/// <summary>
/// Serialize a list of values.
/// </summary>
/// <param name="serializer">The serializer to utilize when serializing the values.</param>
/// <param name="values">The list of values to serialize to the array.</param>
/// <returns>The list of values that make up the array.</returns>
static IEnumerable<JsonValue> SerializeValue(IJsonSerializer serializer, IEnumerable values)
{
foreach (var value in values)
{
yield return serializer.SerializeValue(value);
}
}
示例4: SerializeMembers
/// <summary>
/// Serialize a list of members from the object.
/// </summary>
/// <param name="serializer">The serializer to utilize when serializing the values.</param>
/// <param name="contract">The contract of the object to serialize the members from.</param>
/// <param name="value">The value to serialize the members from.</param>
/// <returns>The list of members that make up the object.</returns>
static IEnumerable<JsonMember> SerializeMembers(IJsonSerializer serializer, IContract contract, object value)
{
foreach (var field in contract.Fields.Where(ShouldSerializeField))
{
yield return new JsonMember(field.Name, serializer.SerializeValue(field.GetValue(value)));
}
}