Beispiel #1
0
 public static void IfEmpty(
     [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)] string value,
     [NotNull][System.Diagnostics.CodeAnalysis.NotNull] string name)
 {
     Fail.RequiresArgumentName(name);
     Fail.IfEmpty(value, Violation.WhenEmpty(name));
 }
 public static void IfNull <T>(
     [CanBeNull][AssertionCondition(AssertionConditionType.IS_NOT_NULL)]
     T value,
     [NotNull][System.Diagnostics.CodeAnalysis.NotNull] string name)
 {
     Fail.RequiresArgumentName(name);
     Fail.IfNull(value, Violation.WhenVariableIsNull(name));
 }
 public static void IfNotEqual <TExpected, TActual>(
     [CanBeNull] TExpected expected,
     [CanBeNull] TActual actual,
     [NotNull][System.Diagnostics.CodeAnalysis.NotNull] string name
     )
 {
     Fail.RequiresArgumentName(name);
     Fail.IfNotEqual(expected, actual, Violation.WhenNotEqual(name, expected, actual));
 }
 public static void IfArgumentEqual <TExpected, TActual>(
     [CanBeNull] TExpected unexpected,
     [CanBeNull] TActual argumentValue,
     [NotNull][System.Diagnostics.CodeAnalysis.NotNull] string argumentName
     )
 {
     Fail.RequiresArgumentName(argumentName);
     Fail.IfEqual(unexpected, argumentValue, Violation.WhenArgumentEqual(argumentName, unexpected));
 }
        public static T FailIfNull <T>(
            [CanBeNull][AssertionCondition(AssertionConditionType.IS_NOT_NULL)][NoEnumeration]
            this T value,
            [NotNull][System.Diagnostics.CodeAnalysis.NotNull] string name)
        {
            Fail.RequiresArgumentName(name);

            return(value.FailIfNull(Violation.WhenVariableIsNull(name)));
        }
Beispiel #6
0
        public static void IfArgumentEqual <TExpected, TActual>([CanBeNull] TExpected unexpected, [CanBeNull] TActual argumentValue, [NotNull] string argumentName)
        {
            Fail.RequiresArgumentName(argumentName);

            if (object.Equals(unexpected, argumentValue))
            {
                throw Fail.Because("Argument '{0}' is equal to {1} and it should NOT be.", argumentName, unexpected);
            }
        }
Beispiel #7
0
        public static string OrFailIfWhiteSpace(
            [CanBeNull][AssertionCondition(AssertionConditionType.IS_NOT_NULL)][NoEnumeration] this string value,
            [NotNull][System.Diagnostics.CodeAnalysis.NotNull] string name)
        {
            Fail.RequiresArgumentName(name);

            Fail.IfWhitespace(value, name);

            return(value);
        }
        public static void IfArgumentNull <T>(
            [CanBeNull][AssertionCondition(AssertionConditionType.IS_NOT_NULL)][NoEnumeration] T argumentValue,
            [NotNull] string argumentName)
        {
            Fail.RequiresArgumentName(argumentName);

            if (argumentValue == null)
            {
                throw Fail.Because("Argument '{0}' was null.", argumentName);
            }
        }
        public static T OrFail <T>(this T?value, [NotNull][System.Diagnostics.CodeAnalysis.NotNull] string name) where T : struct
        {
            Fail.RequiresArgumentName(name);

            if (value == null)
            {
                throw Fail.Because(Violation.WhenVariableIsNull(name));
            }

            return(value.Value);
        }
Beispiel #10
0
        public static void IfArgumentEmpty(
            [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)] string argumentValue,
            [NotNull][System.Diagnostics.CodeAnalysis.NotNull] string argumentName)
        {
            Fail.RequiresArgumentName(argumentName);
            Fail.IfArgumentNull(argumentValue, argumentName);

            if (argumentValue.Length == 0)
            {
                throw Fail.Because(Violation.WhenArgumentEmpty(argumentName));
            }
        }
        //[Obsolete("Use " + nameof(Fail) + "." + nameof(IfNull) + " instead.")]
        public static void IfArgumentNull <T>(
            [CanBeNull][AssertionCondition(AssertionConditionType.IS_NOT_NULL)][NoEnumeration]
            T argumentValue,
            [NotNull][System.Diagnostics.CodeAnalysis.NotNull] string argumentName)
        {
            Fail.RequiresArgumentName(argumentName);

            if (argumentValue == null)
            {
                throw Fail.Because(Violation.WhenArgumentIsNull(argumentName));
            }
        }
Beispiel #12
0
        public static void IfArgumentWhiteSpace(
            [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)] string argumentValue,
            [NotNull][System.Diagnostics.CodeAnalysis.NotNull] string argumentName)
        {
            Fail.RequiresArgumentName(argumentName);
            Fail.IfArgumentNull(argumentValue, argumentName);

            if (string.IsNullOrWhiteSpace(argumentValue))
            {
                throw Fail.Because(Violation.WhenArgumentWhitespace(argumentName));
            }
        }
        public static void IfArgumentWhiteSpace(
            [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)] string argumentValue,
            [NotNull] string argumentName)
        {
            Fail.RequiresArgumentName(argumentName);

            Fail.IfArgumentNull(argumentValue, argumentName);

            if (string.IsNullOrWhiteSpace(argumentValue))
            {
                throw Fail.Because("Argument '{0}' was empty.", argumentName);
            }
        }
        public static T CastEnumOrFail <T>([CanBeNull][NoEnumeration] this Enum value, [NotNull][System.Diagnostics.CodeAnalysis.NotNull] string name)
        {
            Fail.RequiresArgumentName(name);

            Type type = value.GetType();

            if (Enum.IsDefined(type, value) == false)
            {
                throw Fail.Because(Violation.WhenEnumOutOfRange <T>(name, value));
            }

            return(value.CastOrFail <T>(name));
        }
        public static T OrFail <T>(
            [CanBeNull][AssertionCondition(AssertionConditionType.IS_NOT_NULL)][NoEnumeration] this T value,
            [NotNull] string name)
        {
            Fail.RequiresArgumentName(name);

            if (value == null)
            {
                throw Fail.Because("'{0}' is null and it shouldn't be", name);
            }

            return(value);
        }
        public static void IfArgumentEmpty(
            [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)] string argumentValue,
            [NotNull] string argumentName)
        {
            Fail.RequiresArgumentName(argumentName);

            Fail.IfArgumentNull(argumentValue, argumentName);

            if (argumentValue.Length == 0)
            {
                throw Fail.Because("Argument '{0}' was empty.", argumentName);
            }
        }
Beispiel #17
0
        public static T CastEnumOrFail <T>([CanBeNull][NoEnumeration] this Enum value, [NotNull] string name)
        {
            Fail.RequiresArgumentName(name);

            Type type = value.GetType();

            if (Enum.IsDefined(type, value) == false)
            {
                throw Fail.CreateEnumException <T>(value, name);
            }

            return(value.CastOrFail <T>(name));
        }
        public static void IfToLong(
            [CanBeNull] string value,
            int maxLength,
            [NotNull] string name)
        {
            Fail.RequiresArgumentName(name);

            if (value == null)
            {
                return;
            }

            int currentLength = value.Length;

            if (currentLength > maxLength)
            {
                throw Fail.Because("{0} is to long - {1} (max: {2}", name, currentLength, maxLength);
            }
        }
Beispiel #19
0
        public static void IfTooLong(
            [CanBeNull] string value,
            int maxLength,
            [NotNull][System.Diagnostics.CodeAnalysis.NotNull] string name)
        {
            Fail.RequiresArgumentName(name);

            if (value == null)
            {
                return;
            }

            int currentLength = value.Length;

            if (currentLength > maxLength)
            {
                throw Fail.Because(Violation.WhenTooLong(name, currentLength, maxLength));
            }
        }
 public static void IfNotNull <T>([CanBeNull][NoEnumeration] T value, [NotNull][System.Diagnostics.CodeAnalysis.NotNull] string name)
 {
     Fail.RequiresArgumentName(name);
     Fail.IfNotNull(value, Violation.WhenVariableIsNotNull(name));
 }
Beispiel #21
0
        public static void IfArgumentEmpty(Guid value, [NotNull][InvokerParameterName] string argumentName)
        {
            Fail.RequiresArgumentName(argumentName);

            Fail.IfEqual(Guid.Empty, value, "Argument '{0}' is an empty Guid.", argumentName);
        }
Beispiel #22
0
 public static void IfArgumentEmpty(Guid value, [NotNull] string argumentName)
 {
     Fail.RequiresArgumentName(argumentName);
     Fail.IfEmpty(value, Violation.WhenGuidArgumentIsEmpty(argumentName));
 }