目录
2 FilterAttributeOnClassMethod
using System;
using System.Threading.Tasks;
namespace Flatwhite.Core.Tests.Attributes
{
public class BadMethodFilterAttribute : MethodFilterAttribute
{
public override void OnMethodExecuted(MethodExecutedContext methodExecutedContext)
{
throw new Exception($"{nameof(BadMethodFilterAttribute)}.{nameof(OnMethodExecuted)}");
}
public override Task OnMethodExecutedAsync(MethodExecutedContext actionExecutedContext)
{
throw new Exception($"{nameof(BadMethodFilterAttribute)}.{nameof(OnMethodExecutedAsync)}");
}
public override void OnMethodExecuting(MethodExecutingContext methodExecutingContext)
{
throw new Exception($"{nameof(BadMethodFilterAttribute)}.{nameof(OnMethodExecuting)}");
}
public override Task OnMethodExecutingAsync(MethodExecutingContext actionContext)
{
throw new Exception($"{nameof(BadMethodFilterAttribute)}.{nameof(OnMethodExecutingAsync)}");
}
}
}
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace Flatwhite.Core.Tests.Attributes
{
public class FilterAttributeOnClassMethod : MethodFilterAttribute
{
private readonly ILogger _logger;
public FilterAttributeOnClassMethod(ILogger logger)
{
_logger = logger;
}
public override void OnMethodExecuted(MethodExecutedContext methodExecutedContext)
{
methodExecutedContext.InvocationContext[$"{nameof(FilterAttributeOnClassMethod)}.{nameof(OnMethodExecuted)}"] = DateTime.UtcNow;
}
public override Task OnMethodExecutedAsync(MethodExecutedContext methodExecutedContext)
{
methodExecutedContext.InvocationContext[$"{nameof(FilterAttributeOnClassMethod)}.{nameof(OnMethodExecutedAsync)}"] = DateTime.UtcNow;
return Task.CompletedTask;
}
public override void OnMethodExecuting(MethodExecutingContext methodExecutingContext)
{
methodExecutingContext.InvocationContext[$"{nameof(FilterAttributeOnClassMethod)}.{nameof(OnMethodExecutedAsync)}"] = DateTime.UtcNow;
}
public override Task OnMethodExecutingAsync(MethodExecutingContext methodExecutingContext)
{
methodExecutingContext.InvocationContext[$"{nameof(FilterAttributeOnClassMethod)}.{nameof(OnMethodExecutingAsync)}"] = DateTime.UtcNow;
return Task.CompletedTask;
}
}
}