개발/C# .NET

실행중인 클래스명을 조회

xwing 2010. 10. 31. 12:14
재 프로젝트에 있는 모든 UI 클래스 명을 얻어와 보자!

    1 namespace NSCL

    2 {

    3     public partial class Form1 : Form

    4     {

    5         public Form1()

    6         {

    7             InitializeComponent();

    8             this.Load += new EventHandler(Form1_Load);

    9         }

   10 

   11         void Form1_Load(object sender, EventArgs e)

   12         {

   13             GetClassNames();

   14         }

   15 

   16         private void GetClassNames()

   17         {

   18             List<string> clsNames = new List<string>();

   19             Assembly asm = Assembly.GetExecutingAssembly();

   20 

   21             foreach (Type t in asm.GetTypes())

   22             {

   23                 if (t.BaseType.Name == "Form")

   24                 {

   25                     clsNames.Add(t.Name);

   26                 }

   27             }

   28 

   29             listBox1.DataSource = clsNames;

   30         }

   31     }

   32 }


소스는 현재 실행중인 어셈블리를 얻어와서, window Form 클래스를 상속받은 UI 클래스만 가져와
ListBox에 뿌려준다.