I have a method in C# which receives a generic type as argument:
private void DoSomething<T>(T param)
{
//...
}
I need to perform different things depending on what type is param
of. I know I can achieve it with several if
sentences, like this:
private void DoSomething<T>(T param)
{
if (param is TypeA)
{
// do something specific to TypeA case
} else if (param is TypeB)
{
// do something specific to TypeB case
} else if ( ... )
{
...
}
// ... more code to run no matter the type of param
}
Is there a better way of doing this? Maybe with switch-case
or another approach that I'm not aware of?