create class with dynamic properties

D

davidw

I found it seems there is a way to create a class with dynamic properties, I
don't really need define each property?

In ASP.NET, Profile is created with all profile items in web.config as its
properties, I found it has code like this:

public static SettingsPropertyCollection Properties
{
get
{
ProfileBase.InitializeStatic();
return ProfileBase.s_Properties;
}
}

I an not quite sure how it works, but in most case, I would like properties
of some of my class are controlled by code, that means I don't need define
those properties before compilation, could anyone tell me how I do that?

thanks!
 
B

Ben Voigt

davidw said:
I found it seems there is a way to create a class with dynamic properties,
I
don't really need define each property?

In ASP.NET, Profile is created with all profile items in web.config as its
properties, I found it has code like this:

public static SettingsPropertyCollection Properties
{
get
{
ProfileBase.InitializeStatic();
return ProfileBase.s_Properties;
}
}

I an not quite sure how it works, but in most case, I would like
properties
of some of my class are controlled by code, that means I don't need define
those properties before compilation, could anyone tell me how I do that?

I think ASP.NET requires web.config to be available during compilation.

However a Dictionary object will give you just about the effect you are
looking for.
 

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