I ran in to the following:
public void AddConfig<T>(Config c) where T : BaseTypeA
{
// do stuff
}
public void AddConfig<T>(Config c) where T : BaseTypeB
{
// do stuff
}
I would love to be able to do this. But i think it's impossible. The compiler ignores the constraints. Why? (I know it's by design).
I think my 2 options are:
Right?
If you mean in the same class then you are correct (I don't think the compiler checks to make sure BaseTypeA and BaseTypeB can not be converted to each other which is what you would need to check to make sure they are unique methods, i.e. something like where T : BaseTypeA && T !: BaseTypeB
if you get what I mean).
Having said that though, why aren't you doing something like this:
interface IConfigurable
{
void AddConfig(Config c)
}
public class BaseTypeA : IConfigurable
public class BaseTypeB : IConfigurable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With