本文整理汇总了C#中IActionScriptSerializer.ToNative方法的典型用法代码示例。如果您正苦于以下问题:C# IActionScriptSerializer.ToNative方法的具体用法?C# IActionScriptSerializer.ToNative怎么用?C# IActionScriptSerializer.ToNative使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IActionScriptSerializer
的用法示例。
在下文中一共展示了IActionScriptSerializer.ToNative方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetMappedPropertyOrField
/// <summary>
/// Sets a mapped property or field value using reflection.
/// </summary>
/// <param name="serializer"></param>
/// <param name="instance"></param>
/// <param name="propertyOrField"></param>
/// <param name="value"></param>
private static void SetMappedPropertyOrField(IActionScriptSerializer serializer, object instance, MemberInfo propertyOrField, IASValue value)
{
try
{
// Try to set the property.
PropertyInfo property = propertyOrField as PropertyInfo;
if (property != null)
{
object propertyValue = serializer.ToNative(value, property.PropertyType);
property.SetValue(instance, propertyValue, null);
return;
}
// Oh, it must be a field then.
FieldInfo field = (FieldInfo)propertyOrField;
object fieldValue = serializer.ToNative(value, field.FieldType);
field.SetValue(instance, fieldValue);
}
catch (Exception ex)
{
throw new ActionScriptException(String.Format(CultureInfo.CurrentCulture,
"Error while setting value of property or field named '{0}' on class '{1}'",
propertyOrField.Name, propertyOrField.ReflectedType.FullName), ex);
}
}