public void Validate(ValueInfo[] parameters) { var table = new DataTable(); table.CaseSensitive = CaseSensitive; // create a column for each parameter giving its name and type // table.Columns.AddRange( parameters.Select( p => new DataColumn( p.Name, p.Type)).ToArray()); // create one row with all the values // table.Rows.Add(parameters.Select(p => p.Value).ToArray()); // run the expression // var selected = table.Select(Expression); if (!selected.Any()) { throw new ValidationException("Expression failed validation: '{0}' for arguments: [{1}]".FormatWith( Expression, parameters.Select( p => "{0}={1}".FormatWith( p.Name, p.Value.ToSafeString("<NULL>"))).StringJoin(", "))); } }
public void Validate(ValueInfo info) { var str = (string)info.Value; if (str.Length < Length) { throw new ValidationException( string.Format( "Length should be at least {0}", Length)); } }
public void Validate(ValueInfo[] parameters) { // At this point - we already know that all the parameters have a value // that matches their types. // This validator works only for arrays so we'll add // a simple assertion for that. // Debug.Assert(parameters.All(p => p.Value is Array)); // Cast them all to arrays // var arrays = parameters.Select(p => p.Value).Cast<Array>(); // Take the first length // var length = arrays.First().Length; // Validate that all arrays have the same length // if (!arrays.All(a => a.Length == length)) { throw new ValidationException("Not all arrays have the same length."); } }
public void Validate(ValueInfo info) { ValidateUri(info.Value.ToString()); }