Instance Name and Reflection

  • Thread starter Thread starter Scott Eguires
  • Start date Start date
S

Scott Eguires

Is there a way to determine the name of a class instance
using reflection or by some other means? For example
suppose a delegate is fired, I would like to know the name
of the Instance of the suscriber class whose method is
being called:

Say I have two suscriber classes:

dim clsSub1 as CSuscriber
dim clsSub2 as CSuscriber

Then say in the base CSuscriber class I have a method
defined:

Public Sub FireEvent()
' I WANT TO DETERMINE THE NAME OF THE INSTANCE
' Class ASSOCIATED WITH THIS
' i.e,.. If the Instance class is clsSub1 I
' want to output "clsSub1"
End Sub

Thanks,

Scott Eguires
 
* "Scott Eguires said:
Is there a way to determine the name of a class instance
using reflection or by some other means? For example
suppose a delegate is fired, I would like to know the name
of the Instance of the suscriber class whose method is
being called:

Say I have two suscriber classes:

dim clsSub1 as CSuscriber
dim clsSub2 as CSuscriber

Then say in the base CSuscriber class I have a method
defined:

Public Sub FireEvent()
' I WANT TO DETERMINE THE NAME OF THE INSTANCE
' Class ASSOCIATED WITH THIS
' i.e,.. If the Instance class is clsSub1 I
' want to output "clsSub1"
End Sub

Why not extend the subscriber class with a 'Name' property or an
automatically generated, unique ID?
 
Herfried is right.

There is no way to do that, unless you extend the class, and set the name
by yourself.

Remember clasSub1 is the name of a variable which reference the object. You
can have multi variables reference to the same instance. And the instance
never knows who refers to itself.
 
Back
Top