create or extend a class at run time

G

Guest

Hi,

I am trying to use the propertygrid control to show a class.

I have created a class with with numerous browsable properties, and I am
able then to set the propertygrid to show the class.

My issue is that I want to, at run time add new properties to the class, so
I can add or remove items from the class as needed, based on customer
specific configuration that is stored in a database.

Is this possible, and how would I do this ?

Thanks
 
A

Armin Zingler

NoSpamMan said:
Hi,

I am trying to use the propertygrid control to show a class.

I have created a class with with numerous browsable properties, and I
am able then to set the propertygrid to show the class.

My issue is that I want to, at run time add new properties to the
class, so I can add or remove items from the class as needed, based
on customer specific configuration that is stored in a database.

Is this possible, and how would I do this ?


An application cannot write itself. Adding properties is done by a
programmer at design time. Instead, to store a dynamic number of values you
can use one of the many collections:
http://msdn.microsoft.com/en-us/library/0ytkdh4s.aspx

Admittedly, I can not help you with the property grid.


Armin
 
G

Guest

Thanks for your reply.

What if I created a class in code, that contain every possible property I
would ever need.

Could I then create a new class from that one, but with only the properties
I wanted ???

Thanks
 
C

Cor Ligthert[MVP]

We are in the Darwin year.

Have a look at the evolution, the answer is the same.
However, you probably know that it took a lot of time seen from the human
perspective

Cor
 
J

James Hahn

Derived classes inherit properties and methods defined in their base class.

You could build a class in which each property get/set method consulted a
database of some form to decide what the result of setting or getting the
property should be. If the property is to be non-functional in a particular
context, then the attempt to get/set the property would raise an error.
 
T

Tom Shelton

Hi,

I am trying to use the propertygrid control to show a class.

I have created a class with with numerous browsable properties, and I am
able then to set the propertygrid to show the class.

My issue is that I want to, at run time add new properties to the class, so
I can add or remove items from the class as needed, based on customer
specific configuration that is stored in a database.

Is this possible, and how would I do this ?

Thanks

It's possible... System.CodeDom, System.CodeDom.Compiler.

Or, you can create psuedo properties using a Dictionary... Which, is what
I've done in the past...
 

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