473,396 Members | 2,129 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,396 software developers and data experts.

urgent q about PropertyInfo and System.Reflection

Basically, my class has a reference type as one of its property. For
example

- Employee class has a perperty called Name
- Name is a class with string properties - FirstName, LastName, MiddleName,
MaindenName, etc.
- To get to the employee's FirstName, it would be employee.Name.FirstName

At run time, I have the string path to the properties of name
("Name.FirstName", "Name.LastName"); Given an instance of Employee, I
would like to be able to check the values of first and last name.

I know this won't work.

Type type = Type.GetType("Employee");
PropertyInfo pinfo = type.GetProperty("Name.FirstName");

At run time, all I have are the two strings - "Employee" and
"Name.FirstName" (won't go into details as to why I am doing it this way,
but basically I am checking to make sure values of required fields have been
filled out using the list of required fields from a table), and an instance
of Employee. I need to be able to get the value of "Name.FirstName".
Jul 21 '05 #1
1 1444

Reflection doesn't support jumping through multiple levels of
properties in one call like that. You'll basicly have to split up the
"Name.FirstName" at the dot and make chained calls to GetProperty for
each part.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #2

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

Similar topics

2
by: Tony Tullemans | last post by:
I am trying to write a subroutine that will examine all the properties of a form to determine which of those are SqlCommand objects, and then set the Connection property of those SqlCommands to a...
15
by: Charles Law | last post by:
I have adapted the following code from the MSDN help for PropertyInfo SetValue. In the original code, the structure MyStructure is defined as a class MyProperty, and it works as expected. There is...
1
by: David | last post by:
Basically, my class has a reference type as one of its property. For example - Employee class has a perperty called Name - Name is a class with string properties - FirstName, LastName,...
0
by: SyZLaB | last post by:
I had a problem using system.reflection.propertyinfo.getvalue in vb - and searched a lots of newsgroups and libraries - but none had the solution to my problem - and it also seamed like many others...
0
by: tatilou | last post by:
Hello, I need add new method to my properties. these methods should give me some attributes coming from my database. I think, to create a class with implement PropertyInfo but I don't know...
2
by: @@Worker | last post by:
can someone write a sample here? thanks "Kevin Spencer" <kevin@DIESPAMMERSDIEtakempis.com> дÈëÏûÏ¢ÐÂÎÅ:%23VUjBemeGHA.1204@TK2MSFTNGP02.phx.gbl... > Use the system.Reflection namespce,...
3
by: ricolee99 | last post by:
Hi everyone, I have a problem that i have been trying to solve for awhile. I'm given a code where the purpose is to create a general dataset mapper. Given any dataset, i have a class,...
9
by: FourEyes | last post by:
I've read that Reflection is slow and shouldn't be used when performance is a concern. In my case, performance is definitely a concern, so I was thinking that I could collect the PropertyInfo...
4
by: Etienne-Louis Nicolet | last post by:
I am working on an error handler class. Within a property set method of a given class property I'd like to pass the PropertyInfo to a function. Imagine something like: Public Class MyClass .......
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...
0
marktang
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,...
0
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
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...
0
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
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,...
0
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...

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.