多级基本调用 [英] Multiple level base calls

查看:84
本文介绍了多级基本调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在访问基础的虚拟方法时遇到了一些麻烦:
类 - 这不是免费的基类。


这是我的基本情况:


=============================== =================== =========

A级

{

公共虚拟字符串PrintMe()

{

返回"原始A" ;;

}

}


B级:A

{

公共覆盖字符串PrintMe()

{

返回Overriden B;

}

}


C类:B

{


公共覆盖字符串PrintMe()

{

return" Overriden C" ;

}


}

=================== =============================== =========


现在,我要做的是从一个C调用A'的实例
PrintMe()方法。我尝试过各种各样的代表,我已经尝试了反映 - 没有运气。它坚持要返回

虚拟调用表的顶部 - C'的PrintMe()。


任何想法或建议?
< br $> b $ b谢谢

- 卢卡斯

解决方案

你为什么要这么做这个?也许还有另一种方法可以获得你想要的

效果,而无需像

那样调用类层次结构。


基本上它是关于在可选择的级别上部署组件。

整个故事有点复杂,但基本上故事是每个

类都有自己的XML方法,存储各种属性和

属于该类的设置。


基本思想是有基类,它们是.NET Compact

框架兼容用户适用于继承

它们并具有广泛GUI等的类。当部署系统时,我们需要

来获取基类的XML ..


无论如何,整个事情太复杂了,不能简单地介绍一下 -

对于如何完成它有很多限制。底线是

我真的需要像我描述的那样去做。


如何使用base.PrintMe来自B'在B中有一个受保护的方法,

调用base.PrintMe()并从C调用该方法。


使用System;


A类

{

public virtual void PrintMe(){Console.WriteLine(" A"); }

}


B级:A

{

public override void PrintMe(){ Console.WriteLine(QUOT; B"); }

protected void BasePrintMe(){base.PrintMe();}

}


class C:B
{

public override void PrintMe(){BasePrintMe(); }


}


class T

{

public static void Main( )

{

A a =新C();

a.PrintMe();

} < br $>
}


问候

Senthil


I''m having some serious trouble accessing a virtual method of a base
class - that is not the immidate base class.

This is the basic situation that I have:

================================================== =========
class A
{
public virtual string PrintMe()
{
return "Original A";
}
}

class B : A
{
public override string PrintMe()
{
return "Overriden B";
}
}

class C : B
{

public override string PrintMe()
{
return "Overriden C";
}

}
================================================== =========

Now, what I''m trying to do is to from an instance of C call A''s
PrintMe() method. I''ve tried various delegate twists, I''ve tried
reflection - without any luck. It insists on returning the top of the
virtual call table - C''s PrintMe().

Any ideas or suggestions?

thanks
--Lucas

解决方案

Why do you want to do this? Maybe there is another way to get the
effect you want, without having to call up the class hierarchy like
that.


Basically it''s about deploying components on a selectable level. The
whole story is a bit complicated, but basically the story is that each
class has its own to/from XML methods that store various properties and
settings that belong to the class.

The basic idea is that there are base classes, which are .NET Compact
framework compatible while the user works with classes that inherit
them and have extensive GUI etc. When the system is deployed, we need
to get the XML of the base classes..

Anyway, the whole thing is too complicated to briefly cover here -
there''s a bunch of restrictions on how it can be done. Bottom line is
that I really need to do it the way I described it.


How about using base.PrintMe from B? Have a protected method in B that
calls base.PrintMe() and call that method from C.

using System;

class A
{
public virtual void PrintMe() { Console.WriteLine("A"); }
}

class B : A
{
public override void PrintMe() { Console.WriteLine("B"); }
protected void BasePrintMe() { base.PrintMe();}
}

class C : B
{
public override void PrintMe() { BasePrintMe(); }

}

class T
{
public static void Main()
{
A a = new C();
a.PrintMe();
}
}

Regards
Senthil


这篇关于多级基本调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆