I have seen answers on SO with similar questions but did not find one addressing all criteria below.
How can I determine whether class B meets the following criteria when B inherits from A:
[B]
does not implement any[additional]
interfaces (generic or not).[A]
implements a generic interface with its own type as the generic parameter?
The following
object o = new SomeObject();
bool result = (o.GetType().GetInterfaces()[0] == typeof(IKnownInterface<???>));
// ??? should be typeof(o). How to achieve this?
I know I can get the interface name string from the type which is something like "NameSpace.ClassName+IKnownInterface'1[[SomeType, ModuleName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"
but this does not seem intuitive or safe. Plus the '1
notation is incremental based on the number of generic types used for that interface.
I am either going about this the wrong way or missing something silly here. Please advise.