Say I have the following class:
public class General<T> { }
And I want to find out if an object is of that type.
I know I can use reflection to find out whether the object is of that generic type with Type.GetGenericTypeDefinition
, but I want to avoid that.
Is it possible to do something like obj is General<T>
, or obj.GetType().IsAssignableFrom(typeof(General<T>))
?
I'm quite surprised that I couldn't find a similar question, although I may have used wrong keywords in my searches.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…