Well, my problem is that I am creating an api using aspnetcore 2.1, to avoid code duplication I have created an abstract class with the properties that share the dtos (board, boardforcreation, boardforupdate, etc). I added to the abstract class personalized validation using ivalidatableobject, now, I want to add personalized validation to the classes that derive from the abstract class but it tells me that extending from ivalidatableobject interface is rebundant because it was already declared in the base class and also when I add the Validate method in the derived class it tells me that it is already declared and implemented, then, how can I add validation in an abstract class and in a derived class using ivalidatableobject? or is there another way to achieve this. Thank you in advance.
public class Board : BoardAbstractBase, IValidatableObject
{
public Guid BoardId { get; set; }
public DateTimeOffset StartDate { get; set; }
public DateTimeOffset EndDate { get; set; }
}
public abstract class BoardAbstractBase : AbstractBasicEntity, IValidatableObject
{
public DateTimeOffset EstimatedStartDate { get; set; }
public DateTimeOffset EstimatedEndDate { get; set; }
public decimal EstimatedBudget { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (!(EstimatedStartDate < EstimatedEndDate))
yield return new ValidationResult(
"StartDateBeforeEndDate|The estimated start date should be smaller than the end date.",
new[] {"BoardAbstractBase"});
}
}