Home All Groups Group Topic Archive Search About

Inherited form Name from Base

Author
18 Dec 2006 6:37 PM
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

Author
18 Dec 2006 6:42 PM
lord.zoltar
Maybe try:
MyBase.Name
Author
19 Dec 2006 10:33 AM
Phill W.
ScottL wrote:
> 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.
Author
2 Jan 2007 5:25 PM
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

Show quoteHide quote
"ScottL" <scott.loo***@gmail.com> wrote in message
news:1166467068.123859.258150@j72g2000cwa.googlegroups.com...
> 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
>