473,322 Members | 1,287 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,322 software developers and data experts.

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

Nov 17 '05 #1
2 3040
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

Nov 17 '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

Nov 17 '05 #3

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

Similar topics

2
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...
6
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
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...
6
by: ORC | last post by:
I will use FieldInfo to import values from a XML file into the fields of an objects. But how to convert to the proper type like in this: public void Load(object MyClass) { foreach( FieldInfo...
5
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
by: SenthilVel | last post by:
how to get the corresponding values for a given Key in hashtable ??
2
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...
3
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
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
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.