Comparing types including base types in C#
c#, comparison, types
Solution
You should do:
if (e is CommunicationException)
is operator
Problem
If I catch exception, it catches type and its base types too: ``` try { throw new EndpointNotFoundException(...); } catch (CommunicationException e) { // EndpointNotFoundException is caught (inherits from CommunicationException) } ``` But how can I compare types in the same manner? ``` var e = new EndpointNotFoundException(...); if (e.GetType() == typeof(CommunicationException)) // is not true { } ``` I know I can watch `Type.BaseType`, but is not there easiest way how to match types including its base type tree?