protected override IValidator GetValidator(Type targetType)
{
IValidator validator = null;
// NOTE: Patch for performance issue the validator of a viewmodel must be in the same assembly of the view model.
var assembly = targetType.GetAssemblyEx();
var exportedTypes = assembly.GetExportedTypesEx();
var validatorTypes = new List<Type>();
foreach (var exportedType in exportedTypes)
{
if (typeof(FluentValidation.IValidator).IsAssignableFromEx(exportedType))
{
var currentType = exportedType;
bool found = false;
while (!found && currentType != typeof(object))
{
if (currentType != null)
{
var typeInfo = currentType.GetTypeInfo();
var genericArguments = currentType.GetGenericArgumentsEx();
found = typeInfo.IsGenericType && genericArguments.FirstOrDefault(type => type.IsAssignableFromEx(targetType)) != null;
if (!found)
{
currentType = typeInfo.BaseType;
}
}
}
if (found)
{
validatorTypes.Add(exportedType);
}
}
}
if (validatorTypes.Count > 0)
{
validator = FluentValidatorToCatelValidatorAdapter.From(validatorTypes);
}
return validator;
}