目录
1.3 /// This will be called via Reflection
private void HandleSync(IReadOnlyList<MethodFilterAttribute> filterAttributes, IReadOnlyList<ExceptionFilterAttribute> exceptionFilterAttributes, MethodExecutingContext methodExecutingContext)
{
foreach (var f in filterAttributes)
{
try
{
if (methodExecutingContext.Result == null) f.OnMethodExecuting(methodExecutingContext);
}
catch (Exception ex)
{
var exContext = new MethodExceptionContext(ex, methodExecutingContext);
HandleException(exceptionFilterAttributes, exContext);
if (!exContext.Handled)
{
throw;
}
}
}
var reversedFilterAttributes = filterAttributes.Reverse();
var methodExecutedContext = new MethodExecutedContext(methodExecutingContext);
foreach (var f in reversedFilterAttributes)
{
try
{
f.OnMethodExecuted(methodExecutedContext);
}
catch (Exception ex)
{
var exContext = new MethodExceptionContext(ex, methodExecutedContext);
HandleException(exceptionFilterAttributes, exContext);
if (!exContext.Handled)
{
throw;
}
}
}
}
private void HandleException(IReadOnlyList<ExceptionFilterAttribute> exceptionFilterAttributes, MethodExceptionContext exceptionContext)
{
foreach (var f in exceptionFilterAttributes)
{
try
{
if (!exceptionContext.Handled)
{
f.OnException(exceptionContext);
}
}
catch (Exception ex)
{
throw new AggregateException(ex.Message, ex, exceptionContext.Exception);
}
}
}
/// <summary>