public static ValidateTarget <TCollection> Contains <TCollection, TItem>([ValidatedNotNull] this ValidateTarget <TCollection> target, TItem valueToCompare, Func <string> getErrorMessage = null)
            where TCollection : IEnumerable <TItem>
        {
            if (target.Value == null || !TypedCollectionProxy <TCollection, TItem> .Contains(target.Value, valueToCompare))
            {
                ExceptionFactory.ThrowException(target.Traits.GenericFailureExceptionType, getErrorMessage != null ? getErrorMessage.Invoke() : ErrorMessageFactory.ShouldContain(target, valueToCompare));
            }

            return(target);
        }
Ejemplo n.º 2
0
        public static ValidateTarget <TDictionary> ContainsKey <TDictionary, TKey, TValue>([ValidatedNotNull] this ValidateTarget <TDictionary> target, TKey valueToCompare, Func <string> getErrorMessage = null)
            where TDictionary : IDictionary <TKey, TValue>
        {
            if (target.Value == null || !target.Value.ContainsKey(valueToCompare))
            {
                ExceptionFactory.ThrowException(target.Traits.GenericFailureExceptionType, getErrorMessage != null ? getErrorMessage.Invoke() : ErrorMessageFactory.ShouldContain(target, valueToCompare));
            }

            return(target);
        }
        public static ValidateTarget <string> Contains([ValidatedNotNull] this ValidateTarget <string> target, string valueToCompare, Func <string> getErrorMessage = null, StringComparison stringComparison = StringComparison.Ordinal)
        {
            if (target.Value == null || target.Value.IndexOf(valueToCompare, stringComparison) < 0)
            {
                ExceptionFactory.ThrowException(target.Traits.GenericFailureExceptionType, getErrorMessage != null ? getErrorMessage.Invoke() : ErrorMessageFactory.ShouldContain(target, valueToCompare));
            }

            return(target);
        }