Esempio n. 1
0
 public static void IfNullOrNotCastable <T>(
     [CanBeNull][NoEnumeration] object value,
     Violation message)
 {
     Fail.IfNull(value, message);
     Fail.IfNotCastable(value, typeof(T), message);
 }
 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 IfNullOrNotCastable <T>(
            [CanBeNull][NoEnumeration] object value,
            [NotNull] string message,
            [NotNull] params object[] args)
        {
            Fail.RequiresMessage(message, args);

            Fail.IfNull(value, message, args);
            Fail.IfNotCastable(value, typeof(T), message, args);
        }
Esempio n. 4
0
        public static void IfEmpty(
            [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)] string value,
            Violation message)
        {
            Fail.IfNull(value, message);

            if (value.Length == 0)
            {
                throw Fail.Because(message);
            }
        }
Esempio n. 5
0
        public static void IfWhitespace(
            [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)] string value,
            Violation message)
        {
            Fail.IfNull(value, message);

            if (string.IsNullOrWhiteSpace(value))
            {
                throw Fail.Because(message);
            }
        }
        public static void IfEmpty(
            [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)] string value,
            [NotNull] string message,
            [NotNull] params object[] args)
        {
            Fail.RequiresMessage(message, args);

            Fail.IfNull(value, message, args);

            if (value.Length == 0)
            {
                throw Fail.Because(message, args);
            }
        }
        public static void IfWhitespace(
            [CanBeNull, AssertionCondition(AssertionConditionType.IS_NOT_NULL)] string value,
            [NotNull] string message,
            [NotNull] params object[] args)
        {
            Fail.RequiresMessage(message, args);

            Fail.IfNull(value, message, args);

            if (string.IsNullOrWhiteSpace(value))
            {
                throw Fail.Because(message, args);
            }
        }
Esempio n. 8
0
        public static T CastOrFail <T>([CanBeNull][NoEnumeration] this object value, [CanBeNull] string name = null)
        {
            Type castType = typeof(T);

            Fail.IfNull(value, Violation.WhenCannotCast <T>(name ?? "object", value));

            if (castType.IsEnum)
            {
                Fail.IfEnumNotDefined <T>(value);
                return((T)Enum.ToObject(castType, value));
            }

            Fail.IfNotCastable <T>(value, Violation.WhenCannotCast <T>(name ?? "object", value));
            return((T)value);
        }
        public static T CastOrFail <T>([CanBeNull][NoEnumeration] this object value, [CanBeNull] string name = null)
        {
            Type castedType = typeof(T);

            Fail.IfNull(value, Fail.notCastableMessageWithName, name ?? "object", castedType, "null");

            if (castedType.IsEnum)
            {
                Fail.IfEnumNotDefined <T>(value);
                return((T)Enum.ToObject(castedType, value));
            }

            Fail.IfNotCastable <T>(value, Fail.notCastableMessageWithName, name ?? "object", castedType, value);
            return((T)value);
        }
Esempio n. 10
0
 public static void IfNullOrNotCastable <T>([CanBeNull][NoEnumeration] object value)
 {
     Fail.IfNull(value, Violation.WhenCannotCast <T>("object", value));
     Fail.IfNotCastable <T>(value, Violation.WhenCannotCast <T>("object", value));
 }
 public static void IfNullOrNotCastable <T>([CanBeNull][NoEnumeration] object value)
 {
     Fail.IfNull(value, Fail.notCastableMessage, typeof(T), "<null>");
     Fail.IfNotCastable <T>(value, Fail.notCastableMessage, typeof(T), value);
 }