示例#1
0
        public static GuardsContext <string> NotEqual(this GuardsContext <string> guardsContext, string toCompare)
        {
            if (guardsContext.Value == toCompare)
            {
                throw new ArgumentException($"String [{guardsContext.Value}] of name [{guardsContext.Name}] cannot be equal [{toCompare}]!");
            }

            return(guardsContext);
        }
示例#2
0
        public static GuardsContext <string> NotNull(this GuardsContext <string> guardsContext)
        {
            if (guardsContext.Value == null)
            {
                throw new ArgumentException($"String [{guardsContext.Name}] cannot be null!");
            }

            return(guardsContext);
        }
示例#3
0
        public static GuardsContext <string> NotEmpty(this GuardsContext <string> guardsContext)
        {
            if (guardsContext.Value == string.Empty)
            {
                throw new ArgumentException($"String [{guardsContext.Name}] cannot be empty!");
            }

            return(guardsContext);
        }
示例#4
0
        public static GuardsContext <string> NotWhitespace(this GuardsContext <string> guardsContext)
        {
            if (guardsContext.Value != null && string.IsNullOrWhiteSpace(guardsContext.Value))
            {
                throw new ArgumentException($"String [{guardsContext.Name}] cannot be whitespace!");
            }

            return(guardsContext);
        }
示例#5
0
        public static GuardsContext <int> NotZero(this GuardsContext <int> guardsContext)
        {
            if (guardsContext.Value == 0)
            {
                throw new ArgumentException($"Int [{guardsContext.Value}] of name [{guardsContext.Name}] cannot be zero!");
            }

            return(guardsContext);
        }
示例#6
0
        public static GuardsContext <int> NotInRange(this GuardsContext <int> guardsContext, int min, int max)
        {
            if (guardsContext.Value >= min && guardsContext.Value <= max)
            {
                throw new ArgumentException($"Int [{guardsContext.Value}] of name [{guardsContext.Name}] cannot be in range: [{min}] to [{max}]!");
            }

            return(guardsContext);
        }
示例#7
0
        public static GuardsContext <int> InRange(this GuardsContext <int> guardsContext, int min, int max)
        {
            if (guardsContext.Value < min || guardsContext.Value > max)
            {
                throw new ArgumentException($"Int [{guardsContext.Value}] of name [{guardsContext.Name}] has to be in range: [{min}] to [{max}]!");
            }

            return(guardsContext);
        }
示例#8
0
        public static GuardsContext <int> Equal(this GuardsContext <int> guardsContext, int toCompare)
        {
            if (guardsContext.Value != toCompare)
            {
                throw new ArgumentException($"Int [{guardsContext.Value}] of name [{guardsContext.Name}] has to be equal [{toCompare}]!");
            }

            return(guardsContext);
        }
示例#9
0
        public static GuardsContext <int> NotPositive(this GuardsContext <int> guardsContext)
        {
            if (guardsContext.Value > 0)
            {
                throw new ArgumentException($"Int [{guardsContext.Value}] of name [{guardsContext.Name}] cannot be positive!");
            }

            return(guardsContext);
        }