public static ValidateTarget <TValue> IsType <TValue>([ValidatedNotNull] this ValidateTarget <TValue> target, Type valueToCompare, Func <string> getErrorMessage = null) { if (valueToCompare == null) { throw new ArgumentNullException(nameof(valueToCompare)); } var targetType = typeof(TValue); if (target.Value != null) { targetType = target.Value.GetType(); } if (!valueToCompare.IsAssignableFrom(targetType)) { ExceptionFactory.ThrowException(target.Traits.GenericFailureExceptionType, getErrorMessage != null ? getErrorMessage.Invoke() : ErrorMessageFactory.ShouldBeType(target, valueToCompare)); } return(target); }