How to safely get the a particular base type of a control?
How to safely get the a particular base type of a control?
I have a user control A which inherits from a concrete base type B which in turn inherits from a generic control C.
I need to check if A inherits from C and currently I'm doing the following:
var cType = typeof(C<>);
var aType = typeof(A);
if (aType.BaseType.BaseType?.Name == cTye.Name)
or
if (aType.BaseType.BaseType?.GetType() == cTye.GetType())
The above works but I was wondering if there's a cleaner way to do this?
1 Answer
1
Take a look at the is-operator.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.