相关疑难解决方法(0)

Type.GetMethods的BindingFlags,不包括属性访问器

假设我有以下程序:

namespace ReflectionTest
{
    public class Example
    {
        private string field;

        public void MethodOne() { }

        public void MethodTwo() { }

        public string Property
        {
            get { return field; }
            set { this.field = value; }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            iterate(typeof(Example));

            Console.ReadLine();
        }

        public static void iterate(Type type)
        {
            MethodInfo[] methods = type.GetMethods(
                BindingFlags.DeclaredOnly |
                BindingFlags.Instance |
                BindingFlags.Public);

            foreach (MethodInfo mi in methods)
            {
                Console.WriteLine(mi.Name);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当我运行程序时,我得到以下输出:

MethodOne
MethodTwo
get_Property
set_Property …

.net reflection

16
推荐指数
1
解决办法
4302
查看次数

如何通过反射获取MethodInfo的基本方法,而不是属性和事件?

我正在对一个物体进行一些反思性的审讯.代码列出了构造函数,属性和方法.GetMethods( )返回属性访问器/ mutator方法和事件添加/删除方法.

我怎样才能得到基本的方法定义?

更新

.IsSpecialName  
Run Code Online (Sandbox Code Playgroud)

是有效财产.谢谢,@汉斯.

.net c# reflection

7
推荐指数
1
解决办法
3336
查看次数

标签 统计

.net ×2

reflection ×2

c# ×1