3 ms·
The signature of GetAllValidators must be: GetAllValidators<T>(); So it's whatever type of T you pass to GetAllValidators.
by louthy 9y ago
The signature of GetAllValidators must be: GetAllValidators<T>();
So it's whatever type of T you pass to GetAllValidators.
- deleted 9y ago[deleted]
- GenericsMotors 9y agoNot 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. :)