473,493 Members | 2,265 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Getting a reference to an object from the corresponding FieldInfo object???

Hello,

having a FieldInfo object I'd like to get a reference to the
corresponding field object. I know the type of the field object (so I
can do a cast if it is required) but I don't know if FieldInfo indeed
provides a reference to the underlying object and how to get it.
Can anyone help out???
Thx.
Bob Rock

Jul 22 '05 #1
2 1400
You can call GetValue on the FieldInfo object.

//example code (I haven't compiled this code so no garuntees)
MyClass m = new MyClass();
FieldInfo fi = m.GetType.GetField("age");
int age = (int)(fi.GetValue(m));

class MyClass
{
public int age = 23;
}

FYI:
You cannot cast the FieldInfo object as it is only metadata of the Field and
not the Field itself. And I don't think the cast operators are overloaded
for you to do this either. Since they don't know what your field type is, I
am not even sure if there is a way for them to provide a cast operator.

"dotnetguy" <an***************@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hello,

having a FieldInfo object I'd like to get a reference to the
corresponding field object. I know the type of the field object (so I
can do a cast if it is required) but I don't know if FieldInfo indeed
provides a reference to the underlying object and how to get it.
Can anyone help out???
Thx.
Bob Rock

Jul 22 '05 #2
Hi,

AFAIK there is no way of doing it, a FieldInfo is related to the type
itself, it has no connection with a particular instance of the given type.

do u have any way to keep the instance from where you called GetType() ?
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"dotnetguy" <an***************@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hello,

having a FieldInfo object I'd like to get a reference to the
corresponding field object. I know the type of the field object (so I
can do a cast if it is required) but I don't know if FieldInfo indeed
provides a reference to the underlying object and how to get it.
Can anyone help out???
Thx.
Bob Rock

Jul 22 '05 #3

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

Similar topics

6
22487
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object...
2
1895
by: Abdessamad Belangour | last post by:
Hi, I want to get the visiblity kind of a FieldInfo object. The "IsPublic" ans "IsPrivate" properties give the required information for public and private visibilities. My questions are: 1. What...
5
1918
by: Sharon | last post by:
Hi to all. How do i reference a class member dynamically? Somthing like: byte i = 35; Button currentButton = this; Thanks, Sharon.
8
59500
by: SenthilVel | last post by:
how to get the corresponding values for a given Key in hashtable ??
2
2122
by: Ric#k | last post by:
Is it possible to reference all the public properties that are in a class within that class's constructor using REFLECTION, and then reference them with a string variable? I have a class that will...
2
3047
by: dotnetguy | last post by:
Hello, having a FieldInfo object I'd like to get a reference to the corresponding field object. I know the type of the field object (so I can do a cast if it is required) but I don't know if...
3
1848
by: nam23 | last post by:
Hi, I'd like to create a List containing all the checkboxes on a form. The thing is, I don't know how many checkboxes there might be. I thought perhaps I could use reflection to look at all of...
11
25382
by: David Veeneman | last post by:
I need to get a parent's private variable from within a control. Here's what I'm doing: I have a control that I want to be able to detect the presence of a particular (System.ComponentModel)...
4
1463
by: colin | last post by:
How can I access a field contained in fieldInfo by reference so I can pass it to a function ? ive tried __refvalue but this needs a type known at compile time, I can access it with SetValue and...
0
6989
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
7157
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
7195
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...
0
7367
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
5453
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,...
1
4889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1400
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.