2011-03-29 4 views
28

아래 메서드에서와 같이 클래스 이름을 문자열로 전달할 때 리플렉션을 사용하여 클래스의 모든 public 메서드를 가져 오는 방법은 무엇입니까? ?리플렉션을 사용하여 클래스 메서드 가져 오기

private MethodInfo[] GetObjectMethods(string selectedObjClass) 
{ 
    MethodInfo[] methodInfos; 
    Assembly assembly = Assembly.GetAssembly(typeof(sampleAdapater)); 
    Type _type = assembly.GetType("SampleSolution.Data.MyData." + selectedObjClass); 

    ///get all the methods for the classname passed as string 

    return methodInfos; 

} 

도와주세요. 감사

답변

42
MethodInfo[] methodInfos = Type.GetType(selectedObjcClass) 
          .GetMethods(BindingFlags.Public | BindingFlags.Instance); 
7
// get all public static methods of given type(public would suffer in your case, only to show how you could other BindingFlags) 
MethodInfo[] methodInfos = _type.GetMethods(BindingFlags.Public | BindingFlags.Static); 

Type.GetMethods Method (BindingFlags)

관련 문제