C#

[C#]클래스 내 멤버 이름 가져오기 예제

선영아 사랑해 2018. 6. 11. 16:44

using System.Reflection;


namespace FormApplication

{

      public class Form

     {

            Type t = typeof(FormApplication.UserClass);

            MemberInfo[] member = t.FindMembers(MemberTypes.Field, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, null, null);


            foreach(MemberInfo m in member)

           {

                    MessageBox.Show(m.Name);    //출력 결과 => sUserName, dt 이름 출력

           }

     }


     public class UserClass

     {

             public static string sUserName = "";

             public static DataTable dt = new DataTable();

     }

}