Link to home
Start Free TrialLog in
Avatar of brdrok
brdrok

asked on

Examining properties and their values during run time

Hi,

I'd like to examing the properties and their values during run time.  For example, let's say I have the two following classes:

public class Student
{
  private string m_name

  public string Name
  {
     get { return m_name; } set { m_name = value; }
  }
}

public class Building
{
  private string m_location;

  public string Location
  {
    get { return m_location; } set { m_location = value; }
}

I would like to create a some sort of a procedure, that takes a class and examines all the available properties along with their assigned values.

In the end, I would have a message that says something like the following:

Class: Person
Properties: Name  Value: John Smith

Class: Building
Properties: Location Values: Ohio

hope I made sense.  If not, please ask away.

thanks
Avatar of Jens Fiederer
Jens Fiederer
Flag of United States of America image

That is the task associated with REFLECTION.

Take a look at the System.Reflection namespace,and you will find the kinds of functions you will need.
Keep in mind that if you are trying to do this for a CLASS, you can only find values of static properties, since the other properties are attached to specific OBJECTS with a class of that type.
ASKER CERTIFIED SOLUTION
Avatar of Jens Fiederer
Jens Fiederer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brdrok
brdrok

ASKER

many thanks for your reply.  it's almost 6pm and i'm brain dead.  i'll try your suggestion first thing tomorrow morning.  Looks promising though.
How did it go?
Avatar of brdrok

ASKER

heya,

in the end, we decided to scrap it altogether.  However, did learn a new thing about reflection stuff.  Many thanks.