약한 동적 코드 접근/제어 기능
class / struct / record / array / interface / enum / delegate / <T> / …
등 모든 객체의 타입에 관한 메타데이터를 담은 class
//💡Type도 결국 class다. 다음과 같이 실수하지 않도록 주의
var t = typeof(string);
Debug.Log(t); // System.String
Debug.Log(t.GetType()); // System.RuntimeType
| 메소드 | 반환 | 내용 |
|---|---|---|
| GetConstructors() | ConstructorInfo[] | 생성자 목록 |
| GetInterfaces() | Type[] | 인터페이스 목록 |
| GetEvents() | EventInfo[] | 이벤트 목록 |
| GetMethods() | MethodInfo[] | 메서드 목록 |
| GetMembers() | MemberInfo[] | 멤버 목록 |
| GetFields() | FieldInfo[] | 필드 목록 |
| GetProperties() | PropertyInfo[] | 프로퍼티 목록 |
| 접근 제한자 | 작동 방식 | 인자 |
|---|---|---|
| DeclaredOnly | CreateInstance | ExactBinding |
| FlattenHierarchy | GetField | OptionalParamBinding |
| IgnoreCase | SetField | |
| IgnoreReturn | GetProperty | |
| Instance | SetProperty | |
| NonPublic | InvokeMethod | |
| Public (기본값) | PutDispProperty | |
| Static | PutRefDispProperty |
//다음과 같이 사용
var t = typeof(string);
var flags = BindingFlags.Public | BindingFlags.Static;
foreach (var item in t.GetMethods(flags))
{
Debug.Log(item.Name);
}

런타임에 타입 정보를 모르고도 인스턴스를 생성 가능
object o = Activator.CreateInstance(type);
object o = Activator.CreateInstance<string>(type); // Generic 버전도 존재는 한다