首页 > 代码库 > 获取DLL中的方法名称
获取DLL中的方法名称
OpenFileDialog obj = new OpenFileDialog();if (obj.ShowDialog() == System.Windows.Forms.DialogResult.OK){ Assembly ass = Assembly.LoadFrom(obj.FileName); foreach(var type in ass.GetTypes()) { MethodInfo[] members = type.GetMethods(BindingFlags.Public | BindingFlags.Instance); foreach (MemberInfo member in members) { Console.WriteLine(type.Name + "." + member.Name); } }}
MethodBase method = MethodBase.GetCurrentMethod();MyAttribute attr = (MyAttribute)method.GetCustomAttributes(typeof(MyAttribute), true)[0] ;string value = http://www.mamicode.com/attr.Value; //Assumes that MyAttribute has a property called ValueYou can also get the MethodBase manually, like this: (This will be faster)MethodBase method = typeof(MyClass).GetMethod("MyMethod");
[MyAttribute("Hello World")]public int MyMethod(){var myAttribute = GetType().GetMethod("MyMethod").GetCustomAttributes(true).OfType<MyAttribute>().FirstOrDefault();}
获取DLL中的方法名称
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。