Пример #1
0
    private void ReflectionEx_02()
    {
        // C# 코드가 빌드되어 어셈블리에 포함되는 경우 그에 대한 모든 정보를 조회 할 수 있는 기술을 '리플렉션' 이라고함!
        NewPerson newPerson = new NewPerson();
        // Assembly asm = Assembly.GetAssembly(typeof(NewPerson));
        Type type = newPerson.GetType();

        Debug.Log($"<color=#321200>타입 : {type.Name}</color>");

        // 클래스에 정의된 생성자 열거
        foreach (ConstructorInfo ctorInfo in type.GetConstructors())
        {
            Debug.Log($"<color=#110f22>생성자 : {ctorInfo.Name}</color>");
        }

        // 클래스에 정의된 이벤트 열거
        foreach (EventInfo eventInfo in type.GetEvents())
        {
            Debug.Log($"<color=#fcc01f> 이벤트 : {eventInfo.Name}</color>");
        }

        // 클래스에 정의된 필드 열거
        foreach (FieldInfo fieldInfo in type.GetFields())
        {
            Debug.Log($"<color=#44c3fa> 필드 : {fieldInfo.Name}</color>");
        }

        // 클래스에 정의된 메서드 열거
        foreach (MethodInfo method in type.GetMethods())
        {
            Debug.Log($"<color=#ffc1a0> 메소드 : {method.Name}</color>");
        }

        // 클래스에 정의된 프로퍼티 열거
        foreach (PropertyInfo property in type.GetProperties())
        {
            Debug.Log($"<color=#1231ff> 프로퍼티 : {property.Name}</color>");
        }
    }