private static void AddModelValidation(this ValidationContext validationContext, IModel model, List<IModel> handledModels)
{
Argument.IsNotNull("validationContext", validationContext);
if (handledModels.Any(x => ReferenceEquals(x, model)))
{
return;
}
handledModels.Add(model);
validationContext.SynchronizeWithContext(model.ValidationContext, true);
var propertyDataManager = PropertyDataManager.Default;
var catelTypeInfo = propertyDataManager.GetCatelTypeInfo(model.GetType());
foreach (var property in catelTypeInfo.GetCatelProperties())
{
var propertyValue = model.GetValue(property.Key);
var enumerable = propertyValue as IEnumerable;
if (enumerable != null && !(propertyValue is string))
{
foreach (var item in enumerable)
{
var modelItem = item as IModel;
if (modelItem != null)
{
validationContext.AddModelValidation(modelItem, handledModels);
}
}
}
var propertyModel = propertyValue as IModel;
if (propertyModel != null)
{
validationContext.AddModelValidation(propertyModel, handledModels);
}
}
}
}