Can I define interface requirements / dependencies / inheritance programmatically?

Is there a way (reflection or otherwise) to programmatically determine that the IList interface requires ICollection, which in turn requires IEnumerable?

I am working on a reflective library and came across a script where I could use this information, but could not find a way to get it. Both the compiler and the IDE (obviously) know the relationship, so it must be accessible in some way.

I hope for suggestions that are not related to IL or source syntax, none of which are really an option for my use.

+6
source share
2 answers

You can use Type.GetInterfaces to find out this information.

+4
source

Examples below in powershell:

 PS C:\> [collections.ilist].getinterfaces() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True False ICollection True False IEnumerable 

The equivalent in C # would be: typeof(IList).GetInterfaces() .

+1
source

Source: https://habr.com/ru/post/899837/


All Articles