怎么样能得到一个类的全部静态方法并打印

.Net技术 码拜 8年前 (2016-05-06) 791次浏览
本人发现下面这个小程序显示,GetType().GetMethods()只返回非静态成员函数。
那么静态的成员和属性,怎么得到呢?

    class V
    {
        public static V operator+(V v1,V v2)
        {
            return new V();
        }
        public void f() { }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var t=typeof(V);
            Console.WriteLine(t.GetMethods().Length);
            foreach (var m in t.GetMethods())
                Console.WriteLine(m.Name);
        }
    }
解决方案

20

t.GetMethods(BindingFlags.Public | BindingFlags.Static)

20

t.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明怎么样能得到一个类的全部静态方法并打印
喜欢 (0)
[1034331897@qq.com]
分享 (0)