Exemple #1
0
        internal static GuardThis <int> AgainstNegative(this GuardThis <int> guard)
        {
            if (guard.Obj < 0)
            {
                throw new ArgumentException("Value should not be less than zero");
            }

            return(guard);
        }
Exemple #2
0
        internal static GuardThis <int> AgainstZero(this GuardThis <int> guard)
        {
            if (guard.Obj == 0)
            {
                throw new ArgumentException("Value should not be zero");
            }

            return(guard);
        }
        internal static GuardThis <Expression> AgainstNonMemberExpression(this GuardThis <Expression> guard)
        {
            if (!(guard.Obj is MemberExpression))
            {
                throw new ArgumentException("Expression expected to be of type 'MemberExpression' but it was not");
            }

            return(guard);
        }
Exemple #4
0
        internal static GuardThis <Type> AgainstNonCrmPlusPlusEntity(this GuardThis <Type> guard)
        {
            if (!typeof(CrmPlusPlusEntity).IsAssignableFrom(guard.Obj))
            {
                throw new ArgumentException("Type was expected to be CrmPlusPlusEntity but it was not");
            }

            return(guard);
        }
        internal static GuardThis <string> AgainstNullOrEmpty(this GuardThis <string> guard, string customErrorMessage = null)
        {
            if (string.IsNullOrEmpty(guard.Obj))
            {
                throw new ArgumentException(customErrorMessage != null
                    ? customErrorMessage
                    : "String was found to be either empty or null when it should have a value");
            }

            return(guard);
        }
        internal static GuardThis <string> AgainstSpaces(this GuardThis <string> guard, string customErrorMessage = null)
        {
            if (guard.Obj.Trim().Contains(" "))
            {
                throw new ArgumentException(customErrorMessage != null
                    ? customErrorMessage
                    : "String was found to be contain white space, but white space is not allowed");
            }

            return(guard);
        }