Inherited form Name from Base

S

ScottL

Is there any way to get the name of an inheriting object in the item it
is inheriting from? In my case I am looking for a way to get the name
of a form from its base.

For example

Public Class BaseForm
Public Overridable Sub Foo()
'Can I Get the name of the calling obect in here without
passing it?
End Sub
End Class

Public Class InheritedForm
Inherits BaseForm

Public Overrides Sub Foo()
mybase.Foo()
End Sub
End Class
 
P

Phill W.

ScottL said:
Is there any way to get the name of an inheriting object in the item it
is inheriting from?
Public Class BaseForm
Public Overridable Sub Foo()
' Name of the calling object?

Debug.Writeline( Me.Name ) ' "calling" class
Debug.Writeline( MyClass.Name ) ' /this/ class
End Sub
End Class

Public Class InheritedForm
Inherits BaseForm

Public Overrides Sub Foo()
MyBase.Foo()
End Sub
End Class

HTH,
Phill W.
 
S

sstory

I can think of some ugly ways to do it.

One way would be a

mustoverride function GetChildName as string

That way the inheriting class would have to define a function or property if
you prefer to return its name and the base could safely call GetChildName
inside Foo.
You could do the same with an interface if you chose.

I don't know of a quick and easy key word way to do it in VB.NET
 

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