假设我有以下程序:
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 …
我正在对一个物体进行一些反思性的审讯.代码列出了构造函数,属性和方法.GetMethods( )返回属性访问器/ mutator方法和事件添加/删除方法.
我怎样才能得到基本的方法定义?
更新
.IsSpecialName
Run Code Online (Sandbox Code Playgroud)
是有效财产.谢谢,@汉斯.