Reflection question: type name in shared method

J

Jeremy

Hi all,

This is driving me crazy: I am trying to get the name of a child class from
a parent class - the catch is that it's in a shared method. Here is what I
have so far:

Public Class Parent
Public Shared Sub Foo()
' I need to get the child name here, but
' since I can't use the "Me" keyword
' i am having problems

'// This fails because of "Me"
Dim ClassName as String = Me.GetType.Name
End Sub

Public Sub NonSharedMethod( )
'In a non-shared method, here is how I would do it:
Dim ClassName as String = Me.GetType.Name
End Sub
End Class

Public Class Child : Inherits Parent
Public Shared Sub bar( )
Call Foo( )
End Sub
End Class


Thanks,
Jeremy
 
J

Jonas Pohlandt

After a quick look I found:

System.Reflection.MethodInfo.GetCurrentMethod.DeclaringType()

But there's probably a much more elegant way. Just check out
System.Reflection

HTH,

Jonas
 

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