用反射创建一个对象,怎么知道某方法是此对象的方法还是基类的方法? 用反射创建一个对象,怎么知道某方法是此对象的类中定义的方法还是其基类中已有的方法? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 (methodInfo.Attributes & MethodAttributes.Virtual) == MethodAttributes.Virtual//判定是否为虚函数(methodInfo.Attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.VtableLayoutMask//判断是否override class A{ void test();}class B:A{ void test();} var m = typeof(B).GetMethod("test");var isDeclaredInB = m.DeclaringType == typeof(B); class C{ TEST()}class B:C{ TEST();}class etc:B{}...class A:......{ TEST()}再说你怎么知道他的父类的具体名称 public static bool IsMethodDeclaredInType(Type type, string method){ var m = type.GetMethod(method); return m==null? false : m.DeclaringType == type;} 求助textbox控件中如何换行 求助CDT规约中CRC校验码的生成方法??? .net remoting中的new 请问在textbox里怎么控制用户的输入 几个问题 如何在SaveFileDialog上添加自定义的按钮! 如何动态创建一个类文件(CS)的问题? 我总是不太明白委托、接口、结构的区别 怎么把“发送窗口消息”的内窗传到服务端去 高手进来帮我解决一下统一验证问题 请问,如何重写GetHashCode方法 C#word操作的时候怎么样才能分辨到底是文档还是表格
(methodInfo.Attributes & MethodAttributes.Virtual) == MethodAttributes.Virtual
//判定是否为虚函数(methodInfo.Attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.VtableLayoutMask
//判断是否override
void test();
}
class B:A{
void test();
}
var isDeclaredInB = m.DeclaringType == typeof(B);
TEST()}class B:C
{
TEST();
}class etc:B
{}
.
.
.
class A:......
{
TEST()}
再说你怎么知道他的父类的具体名称
{
var m = type.GetMethod(method);
return m==null? false : m.DeclaringType == type;
}