473,574 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get Property Value by Name - is it even possible

Object instance is loaded into process with data in its Fields. There is a
db table, that dictates what properties values are needed for a stored
procedure call.
Is it possible to get value of a propery by its name?

so instead of this:

switch (propertyName)
case "AA" :
x = myObj.AA;
//and so on

I want to do something like this:
x = myObj.PropertyV alueGetter(prop ertyName);

Jan 30 '06 #1
5 19066
Look at the Reflection namespace.

Jan 30 '06 #2
other than that what else is there, or reflections is the only option?

"Bruce Wood" wrote:
Look at the Reflection namespace.

Jan 30 '06 #3
Reflection is about it... why do you ask? Reflection is easy to use
once you get over the (small) learning curve. It does almost exactly
what you wrote:

PropertyInfo pi = myObj.GetType() .GetProperty("A A");
x = pi.GetValue(myO bj, null);

Jan 30 '06 #4
I was just asking if there was another "correct" way of doing it.
using reflections is not a problem for me at all.
Thank you

"Bruce Wood" wrote:
Reflection is about it... why do you ask? Reflection is easy to use
once you get over the (small) learning curve. It does almost exactly
what you wrote:

PropertyInfo pi = myObj.GetType() .GetProperty("A A");
x = pi.GetValue(myO bj, null);

Jan 31 '06 #5
I think you'll find that reflection IS the correct way of doing it.

I would use attributes on desired properties.
For example, an 3 objects might represent 3 tables in a database.
Each of those objects has a different property for the PK: (eg.
obj1.userID obj2.UserAccess LevelID obj3.SalaryRati ngID)
With an attribute called "PK" in front, you could get the value of the
primary key of any of those 3 objects without knowing the name of the
property even.

Of course you may no even be heading in this direction with your
design, so I'll just shut my big mouth.

Jan 31 '06 #6

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

Similar topics

by: Perttu Pulkkinen | last post by:
Hi all php freaks! Do you think this kind of "property class" is useful or not? I have bee bored to the way I've been coding earlier. because: - often i have database-oriented classes like product, category, news etc. - often i have fex. load, request, insert, update and delete functions for them - often problems are the same ones: -...
by: endus | last post by:
I'm having some trouble getting something to work. I'm not even sure whether or not this is possible, but it *seems* like it should be. I've done a fair amount of experimenting and googling...but maybe I'm still missing something obvious... I'm trying to have a <div> appear and disappear based on what a switchbox is set to. Having <div...
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have the properties: mode1, mode2, and mode3. This seems simple but I can't quite figure it out... Any ideas anyone?
by: djake | last post by:
Someone can explain me why to use property get and property set to access a value in a class, insted of access the value directly? What's the usefulness of property statements in VB.NET? Thanks
by: Eric A. Johnson | last post by:
Hi Everyone, I am at my wit's end here. I have a combobox (combyQueryTitle) that I need to use in order to select a query for my database project. Therefore, I am using the comboQueryTitle_SelectedIndexChanged handler to, when a new selection is made, update the query and refresh the display. The only problem is that the program seems to...
by: tomjbr.32022025 | last post by:
I have started looking at the nhibernate framework, but do not really like the string based API which makes it impossible to use automatic refactoring of a property name without the risk of getting problems where the property has been refered to as a string... Therefore I am wondering if it would be even theoretically possible to improve...
by: John Kraft | last post by:
Hi all, I'm trying to use a property grid, and what I'm trying to do seems to really elude me. I've been using the property grid for a short period of time, and this is the first thing I haven't been able to do. I have some products... like t-shirts... and these products have particular property / value pairs. I'd like the property...
by: Nemisis | last post by:
Hi everyone, Can anyone tell me if it is possible to pass in a property of an object into a sub, and within that sub, find out the name of the item that was passed along with the property name?? Example would be ......Code Dim ObjA As New ObjectA
by: josh | last post by:
Hi all, what does it meaning that strange sintax (look at the object :) ? if I have i.e. array.length I can use array. and is it IE/Firefox compatible??
by: | last post by:
Hi, class Resource // This class is autogenerated by Visual Studio. { internal static string M001 { get{ return ResourceManager.GetString("M001"); } } }
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
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...
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...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
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...
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...
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...
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
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.