Mike Cole
Mike Cole

Reputation: 14743

Modifying the default type parameter

I'm utilizing generics as below:

public override ValidationResult SelfValidate()
{
    return ValidationHelper.Validate<VendorValidator, Vendor>(this);
}

However, I can't seem to get the syntax quite right to allow me to pass in a different validator to override the VendorValidator type parameter. I would have expected to be able to use the Type datatype.

Upvotes: 0

Views: 72

Answers (1)

Kenneth
Kenneth

Reputation: 28747

You should add a generic type parameter:

public override ValidationResult SelfValidate<T>()
{
    return ValidationHelper.Validate<T, Vendor>(this);
}

You would use it like this:

this.selfValidate<VendorValidator>();

Note: I see that you're overriding a method. This will not work if you can't change the base method.

Upvotes: 1

Related Questions