factory, Type , factory . , ( IAccount), , factory, , :
public static class ValidatorFactory
{
public static Validator<T> GetValidator<T>(ValidationType validationType)
where T : IValidatable
{
switch (validationType)
{
case ValidationType.AccountCreate:
return new AccountCreateValidator() as Validator<T>;
}
}
}
:
var value = ValidatorFactory.GetValidator<IAccount>(ValidationType.AccountCreate)
AccountCreateValidator Validator<IAccount>.
, , , , , , - , , . ValidatorFactory.GetValidator<IUser>(ValidationType.AccountCreate) .
: - , , , , new AccountCreateValidator() as Validator<T>. , , , , ( , , ). LINQPad, .
I also believe that my previous comment about a possible compilation error, if you pass the wrong generic types, no longer means that casting using the keyword aswill simply return nullif it fails to do so.