Possible Duplicate:
Switch Case on type of object (C#)
I have a method signature that looks like this:
public static TLocalType ToLocalType<TLocalType, TContract>(TContract contract)
{
I would like to be able to do different things based on the actual type of TContract (ie call different methods). Is there a way to do something like this?
switch (TContract)
{
case SomeTypeHere:
Unfortunately, the best you can do is
Note that this includes namespaces.
Note also that it will ignore inheritance and interfaces.
Peter Hallam explains why the language doesn’t support this.