如何将异常传递给方法并在此方法中抛出该类型的异常>
这是我的尝试:
public static void AgainstNull<T, D>(T value, string paramName, D exception, string message)
where T : class
where D : Exception
{
if (value == null)
{
throw new exception(paramName, message);
}
}
和用法:
User user = await this.userManager.FindByNameAsync(assignRoleModel.Username);
Guard.AgainstNull(user, nameof(user), ArgumentNullException, ErrorMessages.FindUserByNameError);