public static void IsEqualTo <T>([NotNull] this Guardian source, [NotNull] Expression <Func <T> > expression, T referenceValue)
        {
            source.IsNotNull(expression, nameof(expression));

            var(value, parameterName) = ((IGuardian)source).ExtractValueAndParameterNameFromExpression(expression);
            IsEqualTo(source, value, parameterName, referenceValue);
        }
 public static void IsNotNullOrEmpty([NotNull] this Guardian source, [NotNull] string value, [NotNull] string parameterName)
 {
     if (string.IsNullOrEmpty(value))
     {
         throw new ArgumentNullException(parameterName, Messages.IsNotNullOrEmptyMessage);
     }
 }
Beispiel #3
0
 public static void IsEqualToZero([NotNull] this Guardian source, long value, [NotNull] string parameterName)
 {
     if (value != 0)
     {
         throw new ArgumentException(Messages.IsEqualToZeroMessage, parameterName);
     }
 }
        public static void IsStrictlyBetween <T>([NotNull] this Guardian source, [NotNull] Expression <Func <T> > expression, T minLimit, T maxLimit, [NotNull] IComparer <T> comparer)
        {
            source.IsNotNull(expression, nameof(expression));

            var(value, parameterName) = ((IGuardian)source).ExtractValueAndParameterNameFromExpression(expression);
            IsLowerThan(source, value, parameterName, maxLimit, comparer);
        }
Beispiel #5
0
        public static void IsLowerThanZero([NotNull] this Guardian source, [NotNull] Expression <Func <double> > expression)
        {
            source.IsNotNull(expression, nameof(expression));

            var(value, parameterName) = ((IGuardian)source).ExtractValueAndParameterNameFromExpression(expression);
            IsLowerThanZero(source, value, parameterName);
        }
Beispiel #6
0
 /// <summary>
 ///     Checks if the specified value is equal to zero.
 /// </summary>
 /// <param name="source">The <see cref="Guardian"/> to extends.</param>
 /// <param name="value">The value.</param>
 /// <param name="parameterName">Name of the parameter.</param>
 public static void IsEqualToZero([NotNull] this Guardian source, double value, [NotNull] string parameterName)
 {
     if (Math.Abs(value - 0) > double.Epsilon)
     {
         throw new ArgumentException(Messages.IsEqualToZeroMessage, parameterName);
     }
 }
        public static void IsNotEmptyGuid([NotNull] this Guardian source, [NotNull] Expression <Func <Guid> > expression)
        {
            source.IsNotNull(expression, nameof(expression));

            var(value, parameterName) = ((IGuardian)source).ExtractValueAndParameterNameFromExpression(expression);
            IsNotEmptyGuid(source, value, parameterName);
        }
Beispiel #8
0
        public static void IsGreaterThanOrEqualTo <T>([NotNull] this Guardian source, [NotNull] Expression <Func <T> > expression, T minLimit, [NotNull] IComparer <T> comparer)
        {
            source.IsNotNull(expression, nameof(expression));

            var(value, parameterName) = ((IGuardian)source).ExtractValueAndParameterNameFromExpression(expression);
            IsGreaterThanOrEqualTo(source, value, parameterName, minLimit, comparer);
        }
 public static void IsNotNull([NotNull] this Guardian source, [NotNull] object value, [NotNull] string parameterName)
 {
     if (value == null)
     {
         throw new ArgumentNullException(parameterName, Messages.IsNotNullMessage);
     }
 }
Beispiel #10
0
        public static void Exists([NotNull] this Guardian source, [NotNull] Expression <Func <FileSystemInfo> > expression)
        {
            source.IsNotNull(expression, nameof(expression));

            var(fileSystemInfo, parameterName) = ((IGuardian)source).ExtractValueAndParameterNameFromExpression(expression);
            Exists(source, fileSystemInfo, parameterName);
        }
Beispiel #11
0
 /// <summary>
 ///     Checks if the specified value is lower than zero.
 /// </summary>
 /// <param name="source">The <see cref="Guardian"/> to extends.</param>
 /// <param name="value">The value.</param>
 /// <param name="parameterName">Name of the parameter.</param>
 public static void IsLowerThanZero([NotNull] this Guardian source, double value, [NotNull] string parameterName)
 {
     if (value >= 0)
     {
         throw new ArgumentOutOfRangeException(parameterName, value, Messages.IsLowerThanZeroMessage);
     }
 }
 /// <summary>
 ///     Checks if the specified <see cref="Guid" /> value is empty
 /// </summary>
 /// <param name="source">The <see cref="Guardian"/> to extends.</param>
 /// <param name="value">The value.</param>
 /// <param name="parameterName">Name of the parameter.</param>
 /// <exception cref="ArgumentException">Thrown when the value is equal to <see cref="Guid.Empty" /></exception>
 public static void IsNotEmptyGuid([NotNull] this Guardian source, Guid value, [NotNull] string parameterName)
 {
     if (value == Guid.Empty)
     {
         throw new ArgumentNullException(parameterName, Messages.IsNotEmptyGuidMessage);
     }
 }
#pragma warning disable CS3024 // Constraint type is not CLS-compliant
        public static void IsDefined <TEnum>([NotNull] this Guardian source, [NotNull] Expression <Func <TEnum> > expression)
#pragma warning restore CS3024 // Constraint type is not CLS-compliant
            where TEnum : struct, IConvertible
        {
            source.IsNotNull(expression, nameof(expression));

            var(value, parameterName) = ((IGuardian)source).ExtractValueAndParameterNameFromExpression(expression);
            IsDefined(source, value, parameterName);
        }
Beispiel #14
0
        public static void Exists([NotNull] this Guardian source, [NotNull] FileSystemInfo file, string parameterName)
        {
            source.IsNotNull(file, nameof(file));

            file.Refresh();
            if (!file.Exists)
            {
                throw new FileNotFoundException(Messages.ExistsNotFoundFormat(parameterName), file.FullName);
            }
        }
Beispiel #15
0
 public static void IsBetween <T>([NotNull] this Guardian source, T value, string parameterName, T minLimit, T maxLimit, IComparer <T> comparer)
 {
     if (comparer == null)
     {
         throw new ArgumentNullException(nameof(comparer), Messages.ComparerNotNullMessage);
     }
     if (comparer.Compare(value, minLimit) < 0 || comparer.Compare(value, maxLimit) > 0)
     {
         throw new ArgumentOutOfRangeException(parameterName, value, Messages.IsBetweenFormat <T>()(minLimit, maxLimit));
     }
 }
 public static void IsEqualTo <T>([NotNull] this Guardian source, T value, [NotNull] string parameterName, T referenceValue,
                                  [NotNull] IComparer <T> comparer)
 {
     if (comparer == null)
     {
         throw new ArgumentNullException(nameof(comparer), Messages.ComparerNotNullMessage);
     }
     if (comparer.Compare(value, referenceValue) != 0)
     {
         throw new ArgumentException(Messages.IsEqualToFormat(referenceValue), parameterName);
     }
 }
        public static void IsEqualTo <T>([NotNull] this Guardian source, T value, [NotNull] string parameterName, T referenceValue)
        {
            var strValue = value as string;

            if (strValue != null)
            {
                IsEqualTo(source, strValue, parameterName, referenceValue as string, StringComparer.CurrentCulture);
            }
            else
            {
                IsEqualTo(source, value, parameterName, referenceValue, Comparer <T> .Default);
            }
        }
Beispiel #18
0
        public static void IsBetween <T>([NotNull] this Guardian source, T value, string parameterName, T minLimit, T maxLimit)
        {
            var stringValue = value as string;

            if (stringValue != null)
            {
                IsBetween(source, stringValue, parameterName, minLimit as string, maxLimit as string, StringComparer.CurrentCulture);
            }
            else
            {
                IsBetween(source, value, parameterName, minLimit, maxLimit, Comparer <T> .Default);
            }
        }
Beispiel #19
0
 public static void IsLowerThan <T>([NotNull] this Guardian source, T value, [NotNull] string parameterName, T maxLimit,
                                    [NotNull] IComparer <T> comparer)
 {
     if (comparer == null)
     {
         throw new ArgumentNullException(nameof(comparer), Messages.ComparerNotNullMessage);
     }
     if (comparer.Compare(value, maxLimit) >= 0)
     {
         throw new ArgumentOutOfRangeException(parameterName, value,
                                               Messages.IsLowerThanFormat <T>()(maxLimit));
     }
 }
Beispiel #20
0
        public static void IsGreaterThanOrEqualTo <T>([NotNull] this Guardian source, T value, [NotNull] string parameterName, T minLimit)
        {
            var strValue = value as string;

            if (strValue != null)
            {
                IsGreaterThanOrEqualTo(source, strValue, parameterName, minLimit as string, StringComparer.CurrentCulture);
            }
            else
            {
                IsGreaterThanOrEqualTo(source, value, parameterName, minLimit, Comparer <T> .Default);
            }
        }
#pragma warning disable CS3024 // Constraint type is not CLS-compliant
        public static void IsDefined <TEnum>([NotNull] this Guardian source, TEnum value, [NotNull] string parameterName)
#pragma warning restore CS3024 // Constraint type is not CLS-compliant
            where TEnum : struct, IConvertible
        {
            var enumType = typeof(TEnum);

            if (!enumType.GetTypeInfo().IsEnum)
            {
                throw new ArgumentException(Messages.IsDefinedType);
            }
            if (!Enum.IsDefined(enumType, value))
            {
                throw new ArgumentOutOfRangeException(Messages.IsDefinedFormat <TEnum>()(value, enumType), parameterName);
            }
        }