I'm implementing a class which i want to inherit it from interface and class. It is working perfect when i use simple class but i want to make it generic. It is giving error when i made it generic. I'm sharing my code please guide me.
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public abstract class ValidateCheckBox<TEntity, Validate, IValidate>
where TEntity : class
where Validate :
ValidationAttribute
where IValidate : IClientValidatable
{
public int MinValue { get; set; }
public ValidateCheckBox(int minValue)
{
MinValue = minValue;
ErrorMessage = "At least " + MinValue + " {0} needs to be checked.";
}
public override string FormatErrorMessage(string propName)
{
return string.Format(ErrorMessage, propName);
}
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
try
{
List<CheckboxInfo> valueList = (List<CheckboxInfo>)value;
foreach (var valueItem in valueList)
{
if (valueItem.Selected)
{
return ValidationResult.Success;
}
}
return new ValidationResult(FormatErrorMessage(validationContext.DisplayName));
}
catch (Exception x)
{
return new ValidationResult(FormatErrorMessage(validationContext.DisplayName));
}
}
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule
{
ErrorMessage = FormatErrorMessage(metadata.GetDisplayName()),
ValidationType = "minchecked",
};
rule.ValidationParameters["minvalue"] = MinValue;
yield return rule;
}
}