Support ValueAccess on all validators

Topics: Validation Application Block
Oct 1, 2007 at 1:59 AM
It would be interesting in a future release to support a ValueAccess on all validators.

By default it would return the incoming object being validated. However, it could allow conversion of the value being validated.


public class Foo
public Func<bool> IsValid { get { return () => true; } }

A FuncValueAccess could invoke the delegate and return the result for validation.

Same with Expression<T>, or why not to support DateTime

Which makes me think it might be more a TypeConverter than a ValueAccess...

Any thoughts?
Oct 1, 2007 at 12:33 PM
Hi Francois,

This is interesting. Can you elaborate a bit more? Would this be similar to method validation?

Oct 1, 2007 at 6:09 PM
As for the Func<T> property type, yeah definitely, it would be the same as a MethodValueAccess+it's related validator.

Something like:

public DelegateValueAccess : ValueAccess
public override bool GetValue(object source, out object value, ...)
// Check for non-void return, parameter-less delegates.
if (source is Delegate) { ... value = ((Delegate)source).Invoke(...); }

However I can see other examples where we would benefit from specifying a valueaccess/typeconverter strategy...

public class Bar
DomainValidator("2000-01-01", ValueAccess=typeof(DateTimeTypeConverter))
public DateTime Date { return DateTime.Now; }

Since DateTime aren't (AFAIK) supported in attributes, we could specify a string and let the converter/accessor convert it before passing the value to the validator.

Oct 19, 2007 at 11:18 PM
Another good example where the ability to specify a ValueAccess would be useful:

When validating a DataRow, an "Indexer" value access could be used to emulate a PropertyValueAccess, accessing the DataRow.Columnsname indexer.