Hiding a static method in a derived class

J

Jose

Hello:
I'm preparing a multitier application, and in the Data Layer I have a
EmployeeRepositoryBase class that has a protected static method called
Fill() and some GetAll() overloaded protected static methods. All GetAll()
static methods call the same Fill() in the base class.

When I want to make a new derived class EmployeeRepository from
EmployeeRepositoryBase, if I want to improve Fill() static method hiding it
with protected static new Fill() I must to rewrite all GetAll() overloaded
methods in the derived class.

If not, when I call to the GetAll() method in the derived class, it uses the
GetAll() method in the base class that uses the Fill() method in the base
class instead of the Fill() method in the derived class.

Is there any way to hide only the Fill() method, and all the static methods
in the base class call to the Fill() method of the derived class?

Thanks in advance
 
C

Christoph Nahr

Is there any way to hide only the Fill() method, and all the static methods
in the base class call to the Fill() method of the derived class?

No. C# (and .NET in general AFAIK) does not support polymorphism with
regards to static members. You must change the original Fill() to a
virtual instance method so that you can override it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top