简体   繁体   中英

In c#, determine interfaces implemented by an object at runtime

I know there are ways to determine at runtime if an object implements a particular interface. What I'm wondering is if there's a way to determine at runtime all of the interfaces an object implements without looking for any one interface in particular.

I'd really rather not have to check for each interface one by one - even using asynchronous processing that seems clunky and inelegant to me.

I'm currently looking into reflection, but if there is a less resource-intensive, in-language way to do it I'd prefer that.

Any ideas?

Type.GetInterfaces will return you the types of the interfaces implemented by the type of an object. For example:

var interfaces = someObject.GetType().GetInterfaces();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM