Reflection

P

Paul

I would like to be able to walk an object and set any properties in the
object at runtime. By 'any' I mean any regardless of their type.

I've gotten reflection working and I can get simple string or numeric
types to work with SetValue, but I'm unsure how to get much further
than that. As just one example, how can I set WebControls.Unit
dynamically? I realize I can create an isntance of that type, but
remember I want to do this at runtime without prior knowledge of the
type.

I'm guessing I need to walk the types and if it is a class type than
build an interface that allows changing properties that I find by
recursively walking it etc.

Any input appreciated...
 
N

Nicholas Paldino [.NET/C# MVP]

Paul,

You will have to have SOME knowledge of the type, and what you want to
do with it. For example, if you want to create types, you might need to be
able to pass parameters to the constructor. How do you specify what those
parameters are?

Other than that, you would set those properties like any other
properties (through the PropertyInfo instance representing the property).

Hope this helps.
 
P

Paul

Well, clearly I'll need to know something, but I'm looking for guidance
about non-obvious thing's I'll run into.

How does the IDE create the property browser for all of the various
types of controls?

For example, the web IDE has a formview border width setting. It
exposes a Unit class which I an call a parse method against or where I
could reflect the properties of. Is there a rule of thumb for any of
this thing? For example, is a useful compromie to see if the object
has a parse method?

I'm looking for techniques or samples to help me deal with the widest
variety of objects possible, just as the IDE property browser can...

Paul,

You will have to have SOME knowledge of the type, and what you want to
do with it. For example, if you want to create types, you might need to be
able to pass parameters to the constructor. How do you specify what those
parameters are?

Other than that, you would set those properties like any other
properties (through the PropertyInfo instance representing the property).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Paul said:
I would like to be able to walk an object and set any properties in the
object at runtime. By 'any' I mean any regardless of their type.

I've gotten reflection working and I can get simple string or numeric
types to work with SetValue, but I'm unsure how to get much further
than that. As just one example, how can I set WebControls.Unit
dynamically? I realize I can create an isntance of that type, but
remember I want to do this at runtime without prior knowledge of the
type.

I'm guessing I need to walk the types and if it is a class type than
build an interface that allows changing properties that I find by
recursively walking it etc.

Any input appreciated...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top