我有以下课程:
public class EntityDoesNotExistException<T> : Exception
{
public T Entity { get; set; }
public EntityDoesNotExistException(T entity, string message = null) : base(message)
{
Entity = entity;
}
}
现在我要验证异常类型:
public class EntityDoesNotExistExceptionAttribute : ExceptionFilterAttribute
{
string _type;
public EntityDoesNotExistExceptionAttribute(string type)
{
_type = type
}
public override void OnException(ExceptionContext context)
{
if (context.Exception != null)
{
var typeName = Type.GetType(_type);
if (context.Exception is EntityDoesNotExistException<typeName>)
{
但不起作用。有什么方法可以验证泛型类型?