获取使用反射类方法 [英] Get class methods using reflection

查看:110
本文介绍了获取使用反射类方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



 私人的MethodInfo [] GetObjectMethods(字符串selectedObjClass)
{
MethodInfo的[] methodInfos;
装配装配= Assembly.GetAssembly(typeof运算(sampleAdapater));
类型类型_ = assembly.GetType(SampleSolution.Data.MyData。+ selectedObjClass);

///获得所有的字符串

返回methodInfos传递的类名的方法;

}

请帮忙。
谢谢


解决方案

 的MethodInfo [] = methodInfos Type.GetType(selectedObjcClass) .GetMethods(BindingFlags.Public | BindingFlags.Instance); 


How can I get all the public methods of class using reflection when class name is passed as a string as shown in the below method. ?

 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;

 }

Please help. Thanks

解决方案

MethodInfo[] methodInfos = Type.GetType(selectedObjcClass) .GetMethods(BindingFlags.Public | BindingFlags.Instance);

这篇关于获取使用反射类方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆