public bool Validate(string key, object item, Dictionary <string, object> optionals, ref Dictionary <string, object> configValues, bool isOptionalValidate) { IEnumerable enumerable = item as IEnumerable; IList arrayValue = arrayValue = new List <IComparable>(); if (DQLHelper.GetValueType(item) != ExtendedJSONDataTypes.Array) { return(false); } if (!enumerable.GetEnumerator().MoveNext()) { return(false); } else { enumerable.GetEnumerator().Reset(); } if (_elementsType is IValidator) { arrayValue = new List <Dictionary <string, object> >(); } foreach (var value in enumerable) { if (_elementsType is ExtendedJSONDataTypes) { if (!DQLHelper.GetValueType(value).Equals(_elementsType)) { return(false); } arrayValue.Add(value); } else if (_elementsType is IValidator) { Dictionary <string, object> elementValues = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); if (!((IValidator)_elementsType).Validate(key, value, optionals, ref elementValues, isOptionalValidate)) { return(false); } arrayValue.Add(elementValues); } } if (!configValues.ContainsKey(key.ToLower())) { configValues.Add(key.ToLower(), arrayValue); } return(true); }
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); }
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); }