Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The signature of GetAllValidators must be: GetAllValidators<T>();

So it's whatever type of T you pass to GetAllValidators.



Not to mention that in the original example IValidator is invariant...it can be far more flexible by making it covariant (IValidator<out T>) so that GetAllValidators can also be used on more derived types.

And then you can do for example:

    var validators = GetAllValidators<EntityBase>();
Where validators might be IEnumerable<IValidator<EntityBase>>. Compile-time type safety is preserved and each individual validator's generic type can be any type that is derived from EntityBase.

:)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: