-2

I want to know how I can get a list of instances of all the inner classes I have in the class of FormStore. I am using .NET 4.5 and C#.

namespace test
{
    public class FormStore
    {


        public partial class child1 : Form
        {

        }

        public partial class child2 : Form
        {

        }

        public partial class child3 : Form
        {

        }

    }
}
Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Amir
  • 1,919
  • 8
  • 53
  • 105
  • 2
    What exactly you are trying to achieve here? You want to know what are all the classes defined under a specific class at runtime? Can you share some relevant details? You can start with exploring reflection. – Chetan Mar 10 '18 at 11:20
  • 2
    Is this what you're asking for ? https://stackoverflow.com/a/5566476/4180382 – Ole EH Dufour Mar 10 '18 at 11:20
  • 1
    Possible duplicate of [Is there a way to get a list of innerclasses in C#?](https://stackoverflow.com/questions/5566428/is-there-a-way-to-get-a-list-of-innerclasses-in-c) – Ofir Winegarten Mar 10 '18 at 11:24
  • @OfirWinegarten: it could be but my problem was when it is extended from Form class how it should be managed. – Amir Mar 10 '18 at 12:32
  • @ChetanRanpariya: I was looking for a way create an instance of my classes dynamically which Esperento57 answered. – Amir Mar 10 '18 at 12:36

1 Answers1

1

Use reflection, like this (more détails here):

 var ListNestedTypes = typeof(test.FormStore).GetTypeInfo().DeclaredNestedTypes;

 foreach (var item in ListNestedTypes)
 {
      string Nameclass = item.Name;
 }
Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Esperento57
  • 16,521
  • 3
  • 39
  • 45