I am having trouble redefining a method that explicitly implements the interface.
I have two classes. The base, called OurViewModel , and the inherited, called MyViewModel . They share a method called Validate , and until recently, I managed to hide the base version of the method, for example:
public class OurViewModel { public bool Validate(ModelStateDictionary modelState){ return true; } } public class MyViewModel : OurViewModel { public new bool Validate(ModelStateDictionary modelState) {return false;} }
All this changed a couple of days ago. A new interface appeared on the scene -
public interface IValidatableObject { IEnumerable<ValidationResult> Validate(ValidationContext validationContext); }
Subsequently, OurViewModel was also changed. I did not ask for this, but it happened, and I have to live with him. The class now looks like this:
public class OurViewModel : IValidatableObject { IEnumerable<ValidationResult> IValidatableObject.Validate(ValidationContext validationContext) {..} }
I find it difficult to determine how to override or hide this rewritten Validate method in MyViewModel. If I try to put the keyword new method signatures (as before), I get a compilation error. I also cannot declare the Validate method as virtual in OurViewModel, as it explicitly implements the interface.
What to do? If I just reimplement Validate in MyViewModel using the signature from the IValidatableObject document, will this hide the implementation in OurViewModel, or am I asking for any problems due to inheritance rules?
source share