Example #1
0
        public override ValidationResult Validate(ValidationContext context, ref object value)
        {
            if (NotEmptyRule.IsEmpty(value, m_valueType))
            {
                value = Default();
            }

            return(null);
        }
Example #2
0
        public override ValidationResult Validate(ValidationContext context, ref object value)
        {
            if (NotEmptyRule.IsEmpty(value))
            {
                return(null);
            }

            foreach (var t in Items)
            {
                if (value.Equals(t))
                {
                    return(context.Issue(this, nameof(ForbiddenRule), $"'{context.ValuePath}' has forbidden [{value.GetType().Name}] value [{value}].").ToResult());
                }
            }

            return(null);
        }
Example #3
0
        public override ValidationResult Validate(ValidationContext context, ref object value)
        {
            if (NotEmptyRule.IsEmpty(value))
            {
                return(null);
            }

            foreach (var t in Values)
            {
                if (value.Equals(t))
                {
                    return(null);
                }
            }

            return(context.Issue(this, nameof(AvailableRule), $"'{context.ValuePath}' doesn't have available values for [{value}].").ToResult());
        }
Example #4
0
        public override ValidationResult Validate(ValidationContext context, ref object value)
        {
            if (value == null || !(value is System.Collections.IEnumerable))
            {
                return(base.Validate(context, ref value));
            }

            var tValue = (value as System.Collections.IEnumerable).Cast <object>().ToList();

            var accum = new List <object>();

            foreach (var t in tValue)
            {
                if (!NotEmptyRule.IsEmpty(t))
                {
                    accum.Add(t);
                }
            }

            if (value is Array)
            {
                var valueAccum = (Array)Activator.CreateInstance(value.GetType(), new object[] { accum.Count });
                for (int i = 0; i < accum.Count; i++)
                {
                    valueAccum.SetValue(accum[i], i);
                }

                value = valueAccum;
                return(null);
            }
            else if (value is System.Collections.IList)
            {
                var valueAccum = (System.Collections.IList)Activator.CreateInstance(value.GetType());
                foreach (var t in accum)
                {
                    valueAccum.Add(t);
                }

                value = valueAccum;
                return(null);
            }

            throw new NotImplementedException();
        }