get name of base class from parent

M

martin

Hi,

If I have a base class, say called "MyBase" and a derived class called
"Myderived" is it possible to get the name of the derived class from the
base class

fo example if I have a method in "MyBase" called "fill" and this method is
not overridden in "Myderived" and I then create and object of my derived and
call the fill method in the base class, the is it possible for the for fill
method of mybase to know it was called from an object of type "Myderived"

what I want to do is set a varable in MyBase.fill to the name of the derived
class (not the name of the instance that called it.)

any help is appreciated.

Thsnk you in advance.

cheers

martin.
 
J

John Saunders

martin said:
Hi,

If I have a base class, say called "MyBase" and a derived class called
"Myderived" is it possible to get the name of the derived class from the
base class

fo example if I have a method in "MyBase" called "fill" and this method is
not overridden in "Myderived" and I then create and object of my derived and
call the fill method in the base class, the is it possible for the for fill
method of mybase to know it was called from an object of type "Myderived"

what I want to do is set a varable in MyBase.fill to the name of the derived
class (not the name of the instance that called it.)

I don't believe you can do this. If "fill" is not overridden in MyDerived,
then it is a MyBase method, and the type of "this" should be MyBase.

On the other hand, I could swear I saw a question like this answered a year
or more ago. I suggest you ask the question again in the
microsoft.public.dotnet.framework newsgroup.
 
K

Ken Dopierala Jr.

Hi Martin,

You could create a MyBase level property and then set this property in the
contructor of your derived class. I've always built my classes so that the
base classes never need to know about a derived class. If I need different
functionality I'll create a MustOveride function or sub and then put the
different functionality in the class that is deriving from the base. Good
luck! Ken.
 
E

Eliyahu Goldin

Martin,

In your example calling this.GetType().ToString() in "fill" should return
the fully qualified name of Myderived.

Eliyahu
 

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