2011年9月20日

.net 继承&多态情况下,调用方法的判断规则

摘要: 从子类开始,一直向父类递归如果方法声明在接口上,那么返回这个方法如果方法声明在父类上,如下所示 如果给定的方法是override,那么返回虚方法 (被override的方法) 如果给定的方法是new的 (注意,默认就是new), 那么将返回该方法本身, (在IL中可以看到newslot) 如果该方法没有被定义在当前类型中,那么返回开始分析当前类的父类以下是原文,我的翻译有改动部分内容If the method is declared on an interface, returns the method.If the method is defined in a base class, ... 阅读全文

posted @ 2011-09-20 22:22 听说读写 阅读(1295) 评论(1) 推荐(0) 编辑

NewSlot and ReuseSlot

摘要: namespace CSharpTester{ class Program { static void Main(string[] args) { var methodA = typeof(A).GetMethod("Test"); PrintAttributes(typeof(System.Reflection.MethodAttributes), (int)methodA.Attributes); var methodB = typeof(B).GetMethod("Test"); ... 阅读全文

posted @ 2011-09-20 21:55 听说读写 阅读(678) 评论(0) 推荐(0) 编辑

导航