Gary

Gary

  • NA
  • 2
  • 0

Accessing Object Properties with a string

Jun 24 2009 10:28 AM

I'm having a bit of trouble with a C# program I'm writing and it'd be great if someone could help.
The background is this, not terribly important, but it's why I need to figure out how to do it:
I'm using a database's Web Services to retrieve information about projects in the database. Each access to the database returns an Project Object with many many properties. However before making the call to the Database, you have tell it what information you want filled in about the project it returns by filling an array of which properties to be retrieved. Any property not in the array is left as it's default value (usually null)
The Problem: I want the user to be able to select a property of an Object (not get the value, just select which property) as below:

projectFields[0] = Primavera.Ws.P6.Project.ProjectFieldType.(project_properties.Text);

where project_properties.Text is a string that names the Object Property I want to assign to projectFields. All Properties of the Object that are indicated in projectFields will be filled out in the return object. For instance, if I wanted the Id and CreatedDate of a project, I'd set up the array as follows

projectFields[0] = Primavera.Ws.P6.Project.ProjectFieldType.Id;
projectFields[1] = Primavera.Ws.P6.Project.ProjectFieldType.CreatedDate;

then when I make the call to the Database, I get back a Project Object, with Id and CreatedDate reflective of the Project I accessed. All other fields are left as their default values (usually Null). I would like to have the ability for the User to choose which fields in the Project Object get retrieved by letting them set a string of the Property they're interested in. I've tried posting in a few other places, but the code they give only allows you to access and retrieve the value of a Property indicated by some string. This is useful, and I'll need it for the returned Project Object, but it doesn't solve my initial problem. If this isn't doable, I could try retrieving everything about the Project Object from the database, but given that most properties aren't important and theres 500+ of them it'd be slow and inefficient. Even if i were to do that however, I'd still have to find a way to create an array of projectFields that is filled out with every property. If this isn't possible in C# is there a language it would be possible in?

 I can't change the way the Database is accessed either because I'm making use of Web Services.

Any help would be greatly appreciated. Thanks.