Beispiel #1
0
        public bool Validate(string key, object item, Dictionary <string, object> optionals,
                             ref Dictionary <string, object> configValues, bool isOptionalValidate)
        {
            if (!(item is IDictionary))
            {
                return(false);
            }

            IDictionary <string, object> doc = (IDictionary <string, object>)item;

            //if (!isOptionalValidate && (doc.Count < Count ||
            //    Count + optionals.Count < doc.Count))
            //{
            //    return false;
            //}

            List <string> extraKeys = new List <string>();

            foreach (var pair in _validators)
            {
                if (!doc.ContainsKey(pair.Key))
                {
                    return(false);
                }

                if (!DQLHelper.KeyInfoEquals(pair.Key, _validators[pair.Key.ToLower()], doc,
                                             optionals, ref configValues, isOptionalValidate))
                {
                    return(false);
                }
            }

            foreach (var pair in _optionalValidators)
            {
                if (!doc.ContainsKey(pair.Key))
                {
                    continue;
                }

                if (!DQLHelper.KeyInfoEquals(pair.Key, _optionalValidators[pair.Key.ToLower()], doc,
                                             optionals, ref configValues, true))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #2
0
        public static bool ValidateOptionals(object item, Dictionary <string, object> optionals, ref Dictionary <string, object> configValues)
        {
            if (!(item is IDictionary))
            {
                return(true);
            }

            IDictionary <string, object> doc = (IDictionary <string, object>)item;

            foreach (var pair in optionals)
            {
                if (doc.ContainsKey(pair.Key))
                {
                    if (!DQLHelper.KeyInfoEquals(pair.Key, optionals[pair.Key.ToLower()], doc,
                                                 new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase), ref configValues, true))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }