Exemple #1
0
        public ValidatorResult Validate(string name, object value) {
            var result = new ValidatorResult();

            if (value == null)
                return result;

            var script = value.ToString();

            if (script == string.Empty)
                return result;

            try {
                var program = _jint.Parse(script, _options);
                if (program != null && program.Errors != null && program.Errors.Any()) {
                    result.Valid = false;
                    foreach (var e in program.Errors) {
                        result.Error("{0}, script: {1}...", e.Message, script.Left(30));
                    }
                }
            } catch (ParserException ex) {
                result.Valid = false;
                result.Error("{0}, script: {1}...", ex.Message, script.Left(30));
            }
            return result;
        }
Exemple #2
0
 public ValidatorResult Validate(string name, object value) {
     var result = new ValidatorResult { Valid = value.ToString().Contains("good") };
     if (!result.Valid) {
         result.Error("The value '{0}' is missing good! I am deeply offended.", value);
     }
     return result;
 }
Exemple #3
0
 public ValidatorResult Validate(string name, object value) {
     var result = new ValidatorResult();
     var count = value.ToString().Split(new[] { '-' }, StringSplitOptions.None).Length - 1;
     result.Valid = count == 2;
     if (!result.Valid) {
         result.Error("The value '{0}' in the '{1}' attribute is no good! It does not have two dashes like we agreed on.", value, name);
     }
     return result;
 }