Daria has added some nice capabilities for the validation of child
collections: http://nhjira.koah.net/browse/NHV-38
Billy
On reflection I am not that comfortable with strongly coupling to the
NHibernate.Validator.
I like the idea of being able to get at the InvalidValue if I need to,
but since the main property needed is PropertyPath.
I was wondering whether we could bake the property into S#arp by:
a) breaking and extending the IValidationResult interface to contain
Property path:
public interface IValidationResult
{
Type ClassContext { get; }
string PropertyName { get; }
string Message { get; }
string PropertyPath { get; }
}
b) providing an inherited interface
public IComplexValidationResult : IValidationResult
{
String PropertyPath { get; }
}
In the case of the ValidationResult implementation of S#arp this would
simply get the InvalidValue.PropertyPath:
public virtual string PropertyPath
{
get { return InvalidValue.PropertyPath; }
}
We could then either have alternative binders and validation adapters or
modify the existing ones to do the following (note there would need to
be a replace of indexing markers [] on PropertyPath to support
scripting, omitted for brevity):
foreach (IValidationResult/IComplexValidationResult validationResult
in validationResults) {
Check.Require(validationResult.ClassContext != null,
"validationResult.ClassContext may not be null");
string key = validationResult.PropertyPath ??
validationResult.ClassContext.Name +
(!string.IsNullOrEmpty(validationResult.PropertyName)
? "." + validationResult.PropertyName
: "");
modelStateDictionary.AddModelError(key,
validationResult.Message);
modelStateDictionary.SetModelValue(key, new
ValueProviderResult(null, null, null));
}
Thoughts?