码迷,mamicode.com
首页 > 其他好文 > 详细

获取DLL中的方法名称

时间:2015-01-12 20:51:15      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

 

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 = attr.Value;    //Assumes that MyAttribute has a property called Value
You 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中的方法名称

标签:

原文地址:http://www.cnblogs.com/xpvincent/p/4219524.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!