using System.Collections.Generic; using System.Web.Mvc; namespace Kreta.Web.Helpers { public static class RequiredIfReflector { public static bool RequiredIf(HtmlHelper helper, IDictionary validationAttributes) { if (validationAttributes.Keys.Contains("data-val-requiredif-dependentproperty") && validationAttributes.Keys.Contains("data-val-requiredif-dependentvalue")) { string dependentPropertyName = (string)validationAttributes["data-val-requiredif-dependentproperty"]; object requiredValue = validationAttributes["data-val-requiredif-dependentvalue"]; var propertyInfo = helper.ViewData.Model.GetType().GetProperty(dependentPropertyName); object dependentPropertyValue = propertyInfo.GetValue(helper.ViewData.Model); return requiredValue.Equals(dependentPropertyValue); } return false; } } }