Assume the following classes
// What I have created ...
public abstract class TaxServiceProvider<T, S>
where T : TaxServiceProviderConfig
where S : TaxServiceInfo
{
protected T Config { get; set; }
public abstract S GetTax(int zipCode);
}
public abstract class TaxServiceInfo { ... }
public abstract class TaxServiceProviderConfig { ... }
// What I want to create ...
public class SpecialTaxServiceProvider<T, S> : TaxServiceProvider<SpecialTaxServiceProviderConfig, SpecialTaxServiceInfo>
where T : SpecialTaxServiceProviderConfig
where S : SpecialTaxServiceInfo
{ ... }
public class SpecialTaxServiceInfo : TaxServiceInfo { ... }
public class SpecialTaxServiceProviderConfig : TaxServiceProviderConfig { ... }
where TaxServiceInfo
and TaxServiceProviderConfig
are used to support the TaxServiceProvider
class.
I want to create a derived class SpecialTaxServiceProvder
(non-abstract) from TaxServiceProvider
that is also generic in the same way that TaxServiceProvider
is and takes SpecialTaxServiceInfo
and SpecialTaxServiceProviderConfig
as the types.
I want to implement GetTax
and Config
in SpecialTaxServiceProvider
so that GetTax
returns type SpecialTaxServiceInfo
and Config
is of type SpecialTaxServiceProviderConfig
I would then create an additional class derived from SpecialTaxServiceProvider
and classes derived from SpecialTaxServiceInfo
and SpecialTaxServiceProviderConfig
public class A_SpecialTaxServiceProvider : SpecialTaxServiceProvider<A_SpecialTaxServiceProviderConfig, A_SpecialTaxServiceInfo>
{ ... }
public class A_SpecialTaxServiceProviderConfig : SpecialTaxServiceProviderConfig { ... }
public class A_SpecialTaxServiceInfo : SpecialTaxServiceInfo { ... }
where GetTax
for this class returns type A_SpecialTaxServiceInfo
and the Config
for this class is of type A_SpecialTaxServiceProviderConfig
I've looked into covariance in C# and the syntax for generic typed classes but I'm not sure if what I'm trying to do is impossible in the language or I just don't know the proper way to set it up.