As per the title. I'd like a list of all the inner classes of a given class, it can be a list of names or a list of types - I am not fussed. Is this possible? I thought there might be a way using reflection but haven't been able to find one.
Java inner class is defined inside the body of another class. Java inner class can be declared private, public, protected, or with default access whereas an outer class can have only public or default access.
Inner classesA inner class declared in the same outer class (or in its descendant) can inherit another inner class.
You want Type.GetNestedTypes. This will give you the list of types, which you can then query for their names.
Doesn't Type.GetNestedTypes
do what you want?
Note that if you want to get "double-nested" types, you'll need to recurse - as Foo.Bar.Baz is a nested type in Foo.Bar, not in Foo.
For "modern" environments (.NET 4.5, PCLs, UWA etc) you need TypeInfo.DeclaredNestedTypes
instead, e.g. type.GetTypeInfo().DeclaredNestedTypes
, using the GetTypeInfo()
extension method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With