C# 使用反射获取类方法

C# 使用反射获取类方法,c#,reflection,C#,Reflection,当类名作为字符串传递时,如何使用反射获取类的所有公共方法,如下面的方法所示 private MethodInfo[] GetObjectMethods(string selectedObjClass) { MethodInfo[] methodInfos; Assembly assembly = Assembly.GetAssembly(typeof(sampleAdapater)); Type _type = assembly.GetType("SampleSoluti

当类名作为字符串传递时,如何使用反射获取类的所有公共方法,如下面的方法所示

 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;

 }
请帮忙。 谢谢

MethodInfo[] methodInfos = Type.GetType(selectedObjcClass) 
                           .GetMethods(BindingFlags.Public | BindingFlags.Instance);
// 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);