/// <summary> /// Validates the value given by the entity and property /// </summary> /// <param name="entity"></param> /// <param name="prop"></param> /// <returns></returns> public override ValidationResult Validate(DomainEntityBase entity, System.Reflection.PropertyInfo prop) { dynamic v = prop.GetValue(entity, null); var retval = new ValidationResult() { Entity = entity, Prop = prop, IsValid = (v != null ? MinValue <= v : true), MemberValue = v, Validation = this, Level = ValidationLevel.Property }; return retval; }
/// <summary> /// Checks <see cref=" Rad.Core.Util.Geo"/> to see if the ILocation is valid. If not, /// compiles a list of recommended spelling corrections. /// </summary> /// <param name="entity"></param> /// <returns></returns> public override ValidationResult Validate(DomainEntityBase entity) { ValidationResult result = new ValidationResult() { Entity = entity, Validation = this, Level = ValidationLevel.Class }; ILocation loc = entity as ILocation; if (loc != null) { if (!(result.IsValid = Geo.IsValid(loc))) { result.Message = Geo.GetRecommendedCorrections(loc); } } return result; }
/// <summary> /// Validates the value given by the entity and property /// </summary> /// <param name="entity"></param> /// <param name="prop"></param> /// <returns></returns> public override ValidationResult Validate(DomainEntityBase entity, PropertyInfo prop) { string v = prop.GetValue(entity, null) as string; ValidationResult result = new ValidationResult() { Entity = entity, MemberValue = v, Prop = prop, Validation = this, Level = ValidationLevel.Property }; if (String.IsNullOrWhiteSpace(v)) { result.IsValid = true; } else { SystemCode sc = SystemCodeManager.GetSystemCode(this.CodeType, v); if (sc == null) { result.IsValid = false; IEnumerable<string> possibleCodes = SystemCodeManager.GetSystemCodesOfType(this.CodeType).Select(a => a.Code); IEnumerable<string> scores = FuzzyStringMatcher.RankByScore(v, possibleCodes).Take(7); scores = scores.Select(s => "\"" + s + "\""); result.Message = String.Format("Possible matches? ({0})", String.Join(", ", scores)); } else { result.IsValid = true; } } return result; }
/// <summary> /// Validates the value given by the entity and property. /// </summary> /// <param name="entity"></param> /// <param name="prop"></param> /// <returns></returns> public override ValidationResult Validate(DomainEntityBase entity, PropertyInfo prop) { string v = prop.GetValue(entity, null) as string ?? String.Empty; ValidationResult result = new ValidationResult() { Entity = entity, Validation = this, MemberValue = v, Prop = prop, Level = ValidationLevel.Property }; if (String.IsNullOrEmpty(v)) { result.IsValid = true; } else { System.Text.RegularExpressions.Regex r; switch (_stdRegex) { case StandardRegexes.Url: Uri u = null; result.IsValid = Uri.TryCreate(v, UriKind.Absolute, out u); break; case StandardRegexes.Email: if (String.IsNullOrWhiteSpace(v)) result.IsValid = true; else { try { MailAddress addr = new MailAddress(v); result.IsValid = true; } catch { result.IsValid = false; } } break; default: r = new System.Text.RegularExpressions.Regex(_regexString); result.IsValid = r.IsMatch(v); break; } } return result; }
/// <summary> /// Validates the value given by the entity and property /// </summary> /// <param name="entity"></param> /// <param name="prop"></param> /// <returns></returns> public override ValidationResult Validate(DomainEntityBase entity, PropertyInfo prop) { string v = prop.GetValue(entity, null) as string; ValidationResult result = new ValidationResult() { Entity = entity, MemberValue = v, Prop = prop, Validation = this, Level = ValidationLevel.Property }; if (!(v is string)) { result.IsValid = false; return result; } if (Allowed.Contains((string)v, CaseSensitive ? StringComparer.InvariantCulture : StringComparer.InvariantCultureIgnoreCase)) { result.IsValid = true; return result; } else { result.IsValid = false; IEnumerable<string> scores = FuzzyStringMatcher.RankByScore(v, Allowed).Take(3); scores = scores.Select(s => "\"" + s + "\""); result.Message = String.Format("Possible matches? ({0})", String.Join(", ", scores)); } return result; }