public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext) { RetryAttribute retryAttribute = (RetryAttribute)input.MethodBase.GetCustomAttributes(typeof(RetryAttribute), false)[0]; IMethodReturn returnValue = DoInvoke(input, getNext); if (returnValue.Exception != null && IsExceptionTypeMatch(returnValue.Exception.GetType(), retryAttribute)) { if (retryTimes >= retryAttribute.RetryTimes) { return(returnValue); } retryTimes++; Invoke(input, getNext); } return(returnValue); }
private bool IsExceptionTypeMatch(Type exceptionType, RetryAttribute retryAttribute) { return(exceptionType == retryAttribute.Type || exceptionType.IsSubclassOf(retryAttribute.Type)); }