473,795 Members | 2,922 Online
Bytes | Software Development & Data Engineering Community
+ 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 1423
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.GetFi eld("age");
int age = (int)(fi.GetVal ue(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.goo glegroups.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.goo glegroups.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
22536
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 instance (in this case 'myDog'). Of course it would be better if I could somehow know from within write() that the name of the object instance was 'myDog' without having to pass it as a parameter. //////////////////////////////// function...
2
1920
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 about "protected" visibility? 2. What exactly do we mean by Family ? Is it a hierarchy of deriving classes? 3. If a field is IsFamily, does it mean it's protected? 4. I tried to get some information through the example of msdn at :...
5
1928
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
59520
by: SenthilVel | last post by:
how to get the corresponding values for a given Key in hashtable ??
2
2141
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 have 35 integer values as public properties that must be read in from a database. Also, each property of this class will have the same name as the column name from the dbase table. For that reason, I would like to just set up a loop to get the...
2
3065
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 FieldInfo indeed provides a reference to the underlying object and how to get it. Can anyone help out??? Thx.
3
1865
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 the fields on the form; if a given field is of type System.Windows.Forms.Checkbox, then I'd add it to the List. But the following code isn't working. .... public formConstructor()
11
25417
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) component on the same form. Components aren't contained in the Form.Controls collection--they are contained in a private Designer variable called 'components'. So, to detect the component, I'm going to need to get to that private variable from the...
4
1481
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 GetValue but in one case where the field is a structure I need to pass it as a ref to a function. as it is a structure i cant make a 'new' copy and pass that as a ref and then copy it back.
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10215
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9043
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7541
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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 we have to send another system
2
3727
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.