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

Get Property Value by Name - is it even possible

Hello,
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;
break;
//and so on
}

I want to do something like this:
x = myObj.PropertyValueGetter(propertyName);

Jan 30 '06 #1
5 19049
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("AA");
x = pi.GetValue(myObj, 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("AA");
x = pi.GetValue(myObj, 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.UserAccessLevelID obj3.SalaryRatingID)
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

4
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...
2
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...
16
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...
62
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
5
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...
1
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...
1
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...
7
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??...
30
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??
4
by: | last post by:
Hi, class Resource // This class is autogenerated by Visual Studio. { internal static string M001 { get{ return ResourceManager.GetString("M001"); } } }
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.