public bool check(out Dictionary <string, ValiResult> result, Dictionary <string, object> opt) { bool r = true; ValiResult vr = null; var safe = new Dictionary <string, object>(); result = new Dictionary <string, ValiResult>(); foreach (var ruleSet in ruleSets) { var k = ruleSet.Key; var v = opt.ContainsKey(k) ? opt[k] : FAIL; ruleSet.Value.setMsg(msg); vr = ruleSet.Value.check(v, safe); result.Add(k, vr); if (vr.result == FAIL) { r = false; } else { safe.Add(k, vr.value); } } return(r); }
internal ValiResult check(object value, Dictionary <string, object> safe) { var r = new ValiResult() { msg = "", result = OK }; if (value == FAIL) { if (!optional) { r.result = FAIL; r.msg = "Cannot found key"; } r.value = null; } else { for (var i = 0; i < rules.Count;) { var item = rules[i++]; var rule = Rule.get(item.rule); if (rule == null) { r.msg = "Cannot found rule. key name is '" + item.rule + "'"; r.result = FAIL; break; } var temp = rule.isValid(value, item.arg, safe); Item logic = AND; if (i < rules.Count) { logic = rules[i++]; } if (temp == FAIL) { if (logic == AND) { var m = item.msg; if (m == "") { m = baseMsg; } var message = msg(m); if (message == null) { r.msg = "error : " + value; } else { r.msg = message.msg(value, item.rule, item.arg, safe); } r.result = FAIL; break; } } else { value = temp; if (logic == OR) { break; } } } r.value = value; } return(r); }