目录
1 MethodInterceptor
1.1 /// This will be called via Reflection
1.2 HandleAsync
///
///
///
///
///
///
private async Task
{
foreach (var f in filterAttributes)
{
try
{
if (methodExecutingContext.Result == null) await f.OnMethodExecutingAsync(methodExecutingContext).ConfigureAwait(false);
}
catch (Exception ex)
{
var exContext = new MethodExceptionContext(ex, methodExecutingContext);
await HandleExceptionAsync(exceptionFilterAttributes, exContext);
if (!exContext.Handled)
{
throw;
}
}
}
var reversedFilterAttributes = filterAttributes.Reverse();
var methodExecutedContext = new MethodExecutedContext(methodExecutingContext);
foreach (var f in reversedFilterAttributes)
{
try
{
await f.OnMethodExecutedAsync(methodExecutedContext).ConfigureAwait(false);
}
catch (Exception ex)
{
var exContext = new MethodExceptionContext(ex, methodExecutedContext);
await HandleExceptionAsync(exceptionFilterAttributes, exContext);
if (!exContext.Handled)
{
throw;
}
}
}
if (methodExecutedContext.Result != null && methodExecutedContext.Result is TResult result)
{
return result;
}
return default(TResult);
}
private async Task HandleAsync(IReadOnlyList
{
foreach (var f in filterAttributes)
{
try
{
if (methodExecutingContext.Result == null) await f.OnMethodExecutingAsync(methodExecutingContext).ConfigureAwait(false);
}
catch (Exception ex)
{
var exContext = new MethodExceptionContext(ex, methodExecutingContext);
await HandleExceptionAsync(exceptionFilterAttributes, exContext);
if (!exContext.Handled)
{
throw;
}
}
}
var reversedFilterAttributes = filterAttributes.Reverse();
var methodExecutedContext = new MethodExecutedContext(methodExecutingContext);
foreach (var f in reversedFilterAttributes)
{
try
{
await f.OnMethodExecutedAsync(methodExecutedContext).ConfigureAwait(false);
}
catch (Exception ex)
{
var exContext = new MethodExceptionContext(ex, methodExecutedContext);
await HandleExceptionAsync(exceptionFilterAttributes, exContext);
if (!exContext.Handled)
{
throw;
}
}
}
}