public static class Helper
{
public static string CheckOverlookedValidation(object obj, string propName)
{
return Helper.CheckOverlookedValidation(obj, propName, null);
}
public static string CheckOverlookedValidation(object obj, string propName, params string[] exceptPropNames)
{
if (exceptPropNames != null)
{
foreach(string epn in exceptPropNames)
{
if (epn == propName)
return null;
}
}
Type t = obj.GetType();
PropertyInfo pi = t.GetProperty(propName);
bool isNullable = !pi.PropertyType.IsValueType;
if (!isNullable)
if (pi.PropertyType.IsGenericType
&& pi.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
isNullable = true;
if (isNullable)
{
object value = t.InvokeMember(propName, System.Reflection.BindingFlags.GetProperty, null, obj, null);
string programmerAlert = "{0} has no custom validation. Alert the Programmer";
if (value == null)
return string.Format(programmerAlert, propName);
else if (pi.PropertyType == typeof(string) && string.IsNullOrWhiteSpace((string)value))
return string.Format(programmerAlert, propName);
else
return null;
}
return null;
}
}