[Mono-list] adding members to a class at runtime

Andreas Färber andreas.faerber at web.de
Mon Dec 19 15:09:31 EST 2005


Hi Yves,

> I need to add members to a class at runtime...
>
> e.g.:
>
> class MyClass {
>     public int var1;
>     public int var2;
>     public int var3;
> }
>
>
> E.g, now, at runtime, I need to add var4 that is a string and var5 
> that is another integer...
>
> Can that be done in c# at all...?

I believe no. But using Reflection.Emit you can derive a class at 
runtime and add the new members and afterwards access all of them.

Regards,

Andreas


More information about the Mono-list mailing list