基本关键字 - 帮助 [英] Base keyword - HELP
问题描述
我有一个实现接口的基类(空中代码):
class BaseClass:SomeInterface
{
void SomeInterface.ImplMethod()
{
// - 此处代码 -
}
}
类派生:SomeInterface
{
void SomeInterface.ImplMethod()
{
//需要在此处调用基础实现
// - 此处代码 -
}
}
如果不公开实现,有办法吗?
TIA
Krishnan
Hi,
Am having a base class that implements an interface (air code) :
class BaseClass : SomeInterface
{
void SomeInterface.ImplMethod()
{
// -- code here --
}
}
class Derived : SomeInterface
{
void SomeInterface.ImplMethod()
{
//NEED TO CALL BASE''S IMPLEMENTATION HERE
// -- code here --
}
}
Without making the implementations public, is there a way to do it?
TIA
Krishnan
推荐答案
> class BaseClass:SomeInterface
> class BaseClass : SomeInterface
class Derived:SomeInterface
class Derived : SomeInterface
派生类不会从基类继承吗?
但是,即使继承,我也找不到一种方法来调用基础
类接口函数。也许其他人知道怎么做?
我只是通过将代码移动到辅助函数来找到解决办法。
像这样:
界面SomeInterface
{
void ImplMethod();
}
类BaseClass:SomeInterface
{
protected void方法(){/ *代码在这里* /}
void SomeInterface.ImplMethod(){Method()}
}
class派生:BaseClass,SomeInterface
{
void SomeInterface.ImplMethod(){base.Method(); }
}
问候,
Wessel
The derived class doesn''t inherit from the base class?
However, even when inheriting, I couldn''t find a way to call the base
class interface function. Maybe someone else knows how to do it?
I only found this work-around, by moving the code to a helper function.
Like this:
interface SomeInterface
{
void ImplMethod();
}
class BaseClass : SomeInterface
{
protected void Method() { /* Code goes here */ }
void SomeInterface.ImplMethod() { Method() }
}
class Derived : BaseClass, SomeInterface
{
void SomeInterface.ImplMethod() { base.Method(); }
}
Greetings,
Wessel
>没有公开实现,有没有办法实现呢?
你的命名有点令人困惑,因为Derived不是来自
BaseClass。但是你可以做到
SomeInterface si = new BaseClass();
si.ImplMethod();
如果这就是你想要的。
Mattias
-
Mattias Sj?gren [MVP ] mattias @ mvps.org
http://www.msjogren.net/dotnet / | http://www.dotnetinterop.com
请回复到新闻组。
>Without making the implementations public, is there a way to do it?
Your naming is a bit confusing since Derived doen''t derive from
BaseClass. But you can do
SomeInterface si = new BaseClass();
si.ImplMethod();
if that''s what you want.
Mattias
--
Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
如果两个类都在同一个程序集中,你可以将方法设为内部
或者你真的派生自那个类并制作受保护的方法。
" Krishnan" < KR ********************* @ myrealbox.com> schrieb im Newsbeitrag
新闻:eO ************** @ tk2msftngp13.phx.gbl ...
You could make the method internal if both classes are in the same assembly
or you really derive from that class and make the method protected.
"Krishnan" <kr*********************@myrealbox.com> schrieb im Newsbeitrag
news:eO**************@tk2msftngp13.phx.gbl...
>我有一个实现接口的基类(空中代码):
类BaseClass:SomeInterface
{
void SomeInterface.ImplMethod()
{
// - 这里的代码 -
}
类派生:SomeInterface
{
void SomeInterface.ImplMethod()
{
//需要在这里打电话给基地的实施
// - 这里的代码 -
}
}
没有实现公众,有办法吗?
TIA
Krishnan
Hi,
Am having a base class that implements an interface (air code) :
class BaseClass : SomeInterface
{
void SomeInterface.ImplMethod()
{
// -- code here --
}
}
class Derived : SomeInterface
{
void SomeInterface.ImplMethod()
{
//NEED TO CALL BASE''S IMPLEMENTATION HERE
// -- code here --
}
}
Without making the implementations public, is there a way to do it?
TIA
Krishnan
这篇关于基本关键字 - 帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!