Create Property on the fly

M

Marc Robitaille

Hello,

Is it possible to add a property to a class on the fly? If yes, How can I do
this or where can I find an exemple?

Thank you

Marc R.
 
C

Cor Ligthert [MVP]

Marc,

A (non static) class is a *template* that you use at design time, so what do
you mean with "on the fly"?

Cor
 
M

Marc Robitaille

Hello Cor,

In my project, I need to create an Enum of a list of files and create a
property from my enum at runtime. I have already found a peace of code to
creates Enum on the fly at runtime but nothing on properties

Thank you
 
R

Robinson

I suspect you don't *need* to create the enum of files but if you told us
more about what you are trying to do we might be able to suggest a better
way.
 
P

Phill W.

Marc said:
In my project, I need to create an Enum of a list of files and create a
property from my enum at runtime.

[IMHO] No; you don't.

There are plenty of ways of doing .. whatever it is you're actually
trying to achieve .. without creating new Types at run-time. Whilst
it's /ever/ so clever that VB can do this, it's a Pain in the Proverbial
to try and work out what happened when it [inevitably] goes wrong.

Since you're working with files, I'd suggest a property that is indexed
by /file name/ as a starting point, probably derived from some sort of
collection base class so that you can iterate through them.

HTH,
Phill W.
 
R

Robinson

Yes, I was thinking "Dictionary" ;)

Phill W. said:
Marc said:
In my project, I need to create an Enum of a list of files and create a
property from my enum at runtime.

[IMHO] No; you don't.

There are plenty of ways of doing .. whatever it is you're actually trying
to achieve .. without creating new Types at run-time. Whilst it's /ever/
so clever that VB can do this, it's a Pain in the Proverbial to try and
work out what happened when it [inevitably] goes wrong.

Since you're working with files, I'd suggest a property that is indexed by
/file name/ as a starting point, probably derived from some sort of
collection base class so that you can iterate through them.

HTH,
Phill W.
 
L

lord.zoltar

Marc said:
Hello Cor,

In my project, I need to create an Enum of a list of files and create a
property from my enum at runtime. I have already found a peace of code to
creates Enum on the fly at runtime but nothing on properties

Just curious, where did you find that code? I don't really need it but
it sounds like a neat trick, and I'd like to see how it works. ;)
 

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