473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Instance Name and Reflection

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
Nov 20 '05 #1
2 1074
* "Scott Eguires" <an*******@discussions.microsoft.com> scripsit:
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 K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
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.

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Angelos Karantzalis | last post by:
Hi y'all ... I've just come across a rather weird problem. i'm using the following code to get the names of the public properties of an object: public static string GetPropertyNames(object...
2
by: Andrzej Kaczmarczyk | last post by:
Hi, I have following problem: (warning, quite long post with lots of code) I have an object of a known type like this. class MyClass { public int Property1; public string Property2; }
5
by: BluDog | last post by:
Hi I have a custom control that displays text, I am trying to work out how to access the name of the instance of the control to display at design time (similar to TextBox). The name property...
6
by: Rene Mansveld | last post by:
Hi, how can I create an instance (object) of a class (form) if I only know the classname (VB.NET 1.0)? I need to do this in a complex app where jobs consist of parts. Each part's data is saved...
20
by: Shawnk | last post by:
I would like to get the class INSTANCE name (not type name) of an 'object'. I can get the object (l_obj_ref.GetType()) and then get the (l_obj_typ.Name) for the class name. I there any way of...
8
by: news.microsoft.com | last post by:
How do I get the class name for a current instance. For example, if I want to know the Class Name for the current form, how do I get this programatically. Thanks
3
by: Chris Pratt | last post by:
I'm sorry to ask such a fundamental question, but is it possible to create a copy of an object in VB.Net 2005? I have an app which, on load, creates an instance of a class, into which it reads a...
4
by: bowser | last post by:
Hello, I'm new to C# but so far I didn't find big problems, except for Reflection. I coudn't find any good material in internet where to study it. If anyone knows about some documents, blogs or...
6
by: =?Utf-8?B?SmFzb24gUmV5bm9sZHM=?= | last post by:
(using .net 2.0) Say you have a class structure like this: class Address .... end class class Person FirstName
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.