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 17 2037
> class BaseClass : SomeInterface class Derived : SomeInterface
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
>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.
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... 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
Thanks for the reply. I missed out on mentioning the base class inheritance
in the derived class.
"Wessel Troost" <no****@like.the.sun> wrote in message
news:op.styc180rxgtv7i@asbel... class BaseClass : SomeInterface class Derived : SomeInterface
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
Just one Q. The line, void SomeInterface.ImplMethod() { Method() }
would call the most derived version's method, right? I mean there is no
"MyClass" keyword in C# :(
TIA
Krishnan
Krishnan "Pay your tax with a smile", says the government. I tried. They
wanted cash.
"Wessel Troost" <no****@like.the.sun> wrote in message
news:op.styc180rxgtv7i@asbel... class BaseClass : SomeInterface class Derived : SomeInterface
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
> class Derived : SomeInterface { void SomeInterface.ImplMethod() { //NEED TO CALL BASE'S IMPLEMENTATION HERE
base.ImplMethod();
// -- code here -- } }
> Just one Q. The line, void SomeInterface.ImplMethod() { Method() } would call the most derived version's method, right? I mean there is no "MyClass" keyword in C# :(
C# does have a "MyClass" keyword: this. You could write:
void SomeInterface.ImplMethod() { this.Method() }
Greetings,
Wessel
> base.ImplMethod();
That doesn't work. Try it.
Greetings,
Wessel
"Krishnan" <kr*********************@myrealbox.com> schrieb im Newsbeitrag
news:eM**************@tk2msftngp13.phx.gbl... Just one Q. The line, void SomeInterface.ImplMethod() { Method() } would call the most derived version's method, right? I mean there is no "MyClass" keyword in C# :(
Why this would be a problem?
In the code of Wessel Troost BaseClass.Method is not virtual, so there never
will be a more derived version.
Christof
Wait, so Dervied DOES or does NOT derive from class Base?
If it does, just use:
base.ImplMethod();
--
Adam Clauss
"Krishnan" <kr*********************@myrealbox.com> wrote in message
news:OR****************@TK2MSFTNGP15.phx.gbl... Thanks for the reply. I missed out on mentioning the base class inheritance in the derived class.
"Wessel Troost" <no****@like.the.sun> wrote in message news:op.styc180rxgtv7i@asbel... class BaseClass : SomeInterface class Derived : SomeInterface
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
> Wait, so Dervied DOES or does NOT derive from class Base? If it does, just use:
base.ImplMethod();
For some reason, that doesn't work if ImplMethod is an interface method.
Greetings,
Wessel
The following works just fine, just tried it (note - if Derived derives from
BaseClass, as mine does then ImplMethod must either be marked as new in
Derived, or virtual in base/override in Derived.):
public interface SomeInterface
{
void ImplMethod();
}
public class BaseClass : SomeInterface
{
public void ImplMethod()
{
Console.WriteLine("BaseClass.ImplMethod");
}
}
public class Derived : BaseClass
{
public new void ImplMethod()
{
base.ImplMethod();
Console.WriteLine("Derived.BaseClass");
}
}
--
Adam Clauss
"Wessel Troost" <no****@like.the.sun> wrote in message
news:op.styi8yiixgtv7i@asbel... Wait, so Dervied DOES or does NOT derive from class Base? If it does, just use:
base.ImplMethod(); For some reason, that doesn't work if ImplMethod is an interface method.
Greetings, Wessel
"Adam Clauss" <ca*****@tamu.edu> schrieb im Newsbeitrag
news:11*************@corp.supernews.com... The following works just fine, just tried it (note - if Derived derives from BaseClass, as mine does then ImplMethod must either be marked as new in Derived, or virtual in base/override in Derived.):
public interface SomeInterface { void ImplMethod(); }
public class BaseClass : SomeInterface { public void ImplMethod() { Console.WriteLine("BaseClass.ImplMethod"); } }
public class Derived : BaseClass { public new void ImplMethod() { base.ImplMethod(); Console.WriteLine("Derived.BaseClass"); } }
-- Adam Clauss
Yes, but that's implicit member implementation and the memeber is public.
The OP said it shall not be public, so he has to use explicit member
implementation.
Christof
> ImplMethod must either be marked as new in Derived, or virtual in base/override in Derived.
Thanks, that was the information I was missing.
Greetings,
Wessel
Oh yes. You are right. I tried a similar workaround with the method marked
virtual and had a confusion. This should work fine (and actually, so should
my case ;) ).
Thanks a ton.
Krishnan
"Christof Nordiek" <cn@nospam.de> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... "Krishnan" <kr*********************@myrealbox.com> schrieb im Newsbeitrag news:eM**************@tk2msftngp13.phx.gbl... Just one Q. The line, void SomeInterface.ImplMethod() { Method() } would call the most derived version's method, right? I mean there is no "MyClass" keyword in C# :( Why this would be a problem? In the code of Wessel Troost BaseClass.Method is not virtual, so there never will be a more derived version.
Christof
"Christof Nordiek" <cn@nospam.de> wrote in message
news:uf**************@TK2MSFTNGP12.phx.gbl... Yes, but that's implicit member implementation and the memeber is public. The OP said it shall not be public, so he has to use explicit member implementation.
Huh? It's an interface method. It MUST be public. There is no other kind.
--
Adam Clauss
Adam Clauss <ca*****@tamu.edu> wrote: "Christof Nordiek" <cn@nospam.de> wrote in message news:uf**************@TK2MSFTNGP12.phx.gbl... Yes, but that's implicit member implementation and the memeber is public. The OP said it shall not be public, so he has to use explicit member implementation.
Huh? It's an interface method. It MUST be public. There is no other kind.
No - if you use explicit interface implementation you end up with a
method which is sort of public and sort of private.
From the language spec:
<quote>
Explicit interface member implementations have different accessibility
characteristics than other members. Because explicit interface member
implementations are never accessible through their fully qualified name
in a method invocation or a property access, they are in a sense
private. However, since they can be accessed through an interface
instance, they are in a sense also public.
</quote>
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jacek Generowicz |
last post by:
Where can I find concise, clear documentation describing what one has
to do in order to enable Python's internal help to be able to provide
descriptions of Python keywords ?
I am in a situation...
|
by: Bob Rock |
last post by:
Hello,
I have read that the base keyword can be used not only to control a base
class instantiation (thus calling one of the base class constructors) but
also to access any other public or...
|
by: Rob Meade |
last post by:
Hi all,
Ok - I'm going around in circles and would appreciate some help.
I have written a windows service, which up until I tried to be clever was
working well :o)
I have a main class which...
|
by: BartlebyScrivener |
last post by:
Using ActivePython 2.4.3 on Windows XP
While in the Pythonwin IDE, if I seek keyword help by issuing the
following command:
>>>help ('while')
I get:
Sorry, topic and keyword...
|
by: jyck91 |
last post by:
// Base Conversion
// Aim: This program is to convert an inputted number
// from base M into base N. Display the converted
// number in base N.
#include <stdio.h>
#include <stdlib.h>...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |