473,486 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using reflection to get instance name

(using .net 2.0)

Say you have a class structure like this:

class Address
....
end class

class Person
FirstName
LastName
MailingAddress as Address
BillingAddress as Address
end class

I'm using reflection to pull out the values at runtime, but I'm having
trouble when I dive into an address. When I'm traversing the object I know
when the type is address and I can get and set values on that instance, but I
can't figure a way to know if I'm looking at the mailing address or the
billing address. Is there a way to get the instance name of an object at
runtime? I've thought about setting a name property in the object, but
that's a bit of a hack and makes things much less reusable. Thanks in
advance.
May 9 '07 #1
2 1565
Also posted in microsoft.public.dotnet.general.csharp

Hi Jason,

It's fine to ask your question in multiple groups, but include all the group
names in one message, rather than posting separately to each one. This saves
people time answering your question if someone in another group has already
answered it.

--
Brian Schwartz
FishNet Components
http://www.fishnetcomponents.com
Fish Grid .NET Light: Powerful Layouts for Small Datasets
"Jason Reynolds" <Ja***********@discussions.microsoft.comwrote in message
news:FA**********************************@microsof t.com...
(using .net 2.0)

Say you have a class structure like this:

class Address
...
end class

class Person
FirstName
LastName
MailingAddress as Address
BillingAddress as Address
end class

I'm using reflection to pull out the values at runtime, but I'm having
trouble when I dive into an address. When I'm traversing the object I
know
when the type is address and I can get and set values on that instance,
but I
can't figure a way to know if I'm looking at the mailing address or the
billing address. Is there a way to get the instance name of an object at
runtime? I've thought about setting a name property in the object, but
that's a bit of a hack and makes things much less reusable. Thanks in
advance.

May 9 '07 #2
Will do. Thanks for the tip.

"Brian Schwartz" wrote:
Also posted in microsoft.public.dotnet.general.csharp

Hi Jason,

It's fine to ask your question in multiple groups, but include all the group
names in one message, rather than posting separately to each one. This saves
people time answering your question if someone in another group has already
answered it.

--
Brian Schwartz
FishNet Components
http://www.fishnetcomponents.com
Fish Grid .NET Light: Powerful Layouts for Small Datasets
"Jason Reynolds" <Ja***********@discussions.microsoft.comwrote in message
news:FA**********************************@microsof t.com...
(using .net 2.0)

Say you have a class structure like this:

class Address
...
end class

class Person
FirstName
LastName
MailingAddress as Address
BillingAddress as Address
end class

I'm using reflection to pull out the values at runtime, but I'm having
trouble when I dive into an address. When I'm traversing the object I
know
when the type is address and I can get and set values on that instance,
but I
can't figure a way to know if I'm looking at the mailing address or the
billing address. Is there a way to get the instance name of an object at
runtime? I've thought about setting a name property in the object, but
that's a bit of a hack and makes things much less reusable. Thanks in
advance.


May 9 '07 #3

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

Similar topics

6
3691
by: kapilp | last post by:
hi, i have a program that used reflection to execute methods. now i want to execute the reflected method on a new thread but cant figure out how or if it can be done. take the below code, for...
4
1628
by: Lucas Sain | last post by:
Hi, I think thta for this I have to use reflection... but I'm not shure. How can I find/get an object at runtime by looking for its name that is stored in a variable. For example: I have a...
8
16848
by: Robert W. | last post by:
I've almost completed building a Model-View-Controller but have run into a snag. When an event is fired on a form control I want to automatically updated the "connnected" property in the Model. ...
1
2209
by: Edward Wilde | last post by:
Hi, Does anyone know how to examine items in the ASP.NET cache that are added using the OutputCache directive in framework 1.1 i.e. <%@ OutputCache Duration="300" VaryByParam="None"...
0
1532
by: Shawn Hogan | last post by:
Hi everyone, I've been trying to execute a control's private event code via reflection from another class with the goal of potentially doing some unit testing. The examples below are trying to...
5
4556
by: Anders Borum | last post by:
Hello! Whilst refactoring an application, I was looking at optimizing a ModelFactory with generics. Unfortunately, the business objects created by the ModelFactory doesn't provide public...
3
3160
by: Mark R. Dawson | last post by:
Hi all, I am trying to get custom attributes from a property. I can do this if I pass in the name of the property i.e. "Name" to the reflection methods, but if I pass in set_Name which is what...
2
3620
by: Luis Arvayo | last post by:
Hi, In c#, I need to dynamically create types at runtime that will consist of the following: - inherits from a given interface - will have a constructor with an int argument
4
3951
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
5
1843
by: | last post by:
I am having problems with casting or converting a class to to an interface from which it derives. I'm certain that it's due to how it's being loaded, but I'm not sure how to get past the problem....
0
7099
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7175
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...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7319
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5430
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3069
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.