First off, I would like to thank myself for solving this problem. Hopefully this answer will help someone in the future.
Basically I created a custom validator that extends the ObjectValidator and added a _PropertyName field which gets prepended to the keys of the validationresults.
So now the usage in the example described above would be:
public class Profile
{
...
[SuiteObjectValidator("HomeAddress")]
public Address HomeAddress { get; set; }
[SuiteObjectValidator("WorkAddress")]
public Address WorkAddress { get; set; }
}
The validator class:
public class SuiteObjectValidator : ObjectValidator
{
private readonly string _PropertyName;
public SuiteObjectValidator(string propertyName, Type targetType)
: base(targetType)
{
_PropertyName = propertyName;
}
protected override void DoValidate(object objectToValidate, object currentTarget, string key,
ValidationResults validationResults)
{
var results = new ValidationResults();
base.DoValidate(objectToValidate, currentTarget, key, results);
foreach (ValidationResult validationResult in results)
{
LogValidationResult(validationResults, validationResult.Message, validationResult.Target,
_PropertyName + "." + validationResult.Key);
}
}
}
And the necessary attribute class:
public class SuiteObjectValidatorAttribute : ValidatorAttribute
{
public SuiteObjectValidatorAttribute()
{
}
public SuiteObjectValidatorAttribute(string propertyName)
{
PropertyName = propertyName;
}
public string PropertyName { get; set; }
protected override Validator DoCreateValidator(Type targetType)
{
var validator = new SuiteObjectValidator(PropertyName, targetType);
return validator;
}
}