News for hackers. Stuff that matters.
Re:How the .NET Runtime Loads a Type by Merad on Friday June 16, 2017 @01:31PM (#14570944)
The question here is, what good is a collection of all validators? If you want to perform validation, you're starting with an item (to validate) and you know its type, so it shouldn't be a problem to get the correct IValidator<T> for it. If you really need to have a common base for all validators, explicit interface implementation is a better choice than hiding methods with new:

    interface IValidator
    {
      bool Validate(object item);
    }
    
    interface IValidator<T> : IValidator
    {
      bool Validate(T item);
    }
    
    abstract class Validator<T> 
      : IValidator<T> where T : class
    {
      public abstract bool Validate(T item);
      
      bool IValidator.Validate(object item)
      {
        var typedItem = item as T;
        if (typedItem == null)
          throw new InvalidOperationException();
        
        return Validate(typedItem);
      }
    }

There are no comments on this comment yet.