• 获取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 = 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();
    }
  • 相关阅读:
    火狐显示不安全链接
    signal信号
    I/O缓冲
    [pe530]GCD of Divisors
    学校寒假集训作业
    纳克萨玛斯「GDOI2007」(网络流)
    [清华集训2016] 汽水
    有上下界网络流
    [AHOI2014]支线剧情(有上下界的网络流)
    [SCOI2016]妖怪
  • 原文地址:https://www.cnblogs.com/xpvincent/p/4219524.html
Copyright © 2020-2023  润新知