C# 从ResultExecutedContext结果获取值

C# 从ResultExecutedContext结果获取值,c#,.net,asp.net-core,httpcontext,C#,.net,Asp.net Core,Httpcontext,如何从ResultExecutedContext结果中获取值? 在调试中,我可以看到以下值: 但情报人员没有看到 使用System.Reflection和JsonResult来达到所需的值。还要将[JsonResultAttribute]添加到控制器操作中 public class JsonResultAttribute : ActionFilterAttribute { public override void OnResultExecuted(ResultExecutedConte

如何从ResultExecutedContext结果中获取值? 在调试中,我可以看到以下值:


但情报人员没有看到

使用
System.Reflection
JsonResult
来达到所需的值。还要将[JsonResultAttribute]添加到控制器操作中

public class JsonResultAttribute : ActionFilterAttribute
{
    public override void OnResultExecuted(ResultExecutedContext filterContext)
    {

        // Detect that the result is of type JsonResult
        if (filterContext.Result is JsonResult)
        {
            var jsonResult = filterContext.Result as JsonResult;

            // Dig into the Data Property
            foreach(var prop in jsonResult.Value.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                var propName = prop.Name;
                var propValue = prop.GetValue(jsonResult.Value,null);

                Console.WriteLine("Property: {0}, Value: {1}",propName,     propValue);

                // Detect if property is an DateTime
                if (propValue is DateTime)
                {
                    // Take some action
                }
            }
        }
    }
}

在监视窗口中按原样强制转换:((Microsoft.AspNetCore.Mvc.ObjectResult)context.Result).Value