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