Omu
Omu

Reputation: 71188

how know if a Type has inherited some other type?

how know if a Type has inherited some other type ?

Type t;
// i get the t from somewhere
bool b = t.IsInhertitedFrom(typeof(BaseType));

Upvotes: 3

Views: 206

Answers (1)

Jarek Kardas
Jarek Kardas

Reputation: 8455

bool b = t.IsSubclassOf(typeof(BaseType))

and to check if type implements interface use:

bool b = t.GetInterface(typeof(IMyInterface).FullName) != null

Upvotes: 12

Related Questions