Groups | Blog | Home
all groups > dotnet clr > august 2004 >

dotnet clr : Updating a dynamically generated type



Eugene
8/1/2004 6:49:22 PM
Hi,

Is there a way to update a dynamically created type without having to
rebuild it from scratch?

I know that once you use the CreateType() method, you cannot define more
methods on a TypeBuilder instance but it is possible to add more types to a
dynamic module.

So say I have a dynamic type which has 100 methods defined in it and has had
CreateType() called on it. Now I want to add another method to it. Is there
any way to leverage the existing type when creating the updated type or do I
have to redefine all the 100 + 1 methods on the new type?

Thanks.


pdrayton NO[at]SPAM online.microsoft.com
8/2/2004 6:09:22 PM
| Is there a way to update a dynamically created type without having to
| rebuild it from scratch?

No, not when you are defining new types using Reflection.Emit.

| So say I have a dynamic type which has 100 methods defined in it and has
had
| CreateType() called on it. Now I want to add another method to it. Is
there
| any way to leverage the existing type when creating the updated type or
do I
| have to redefine all the 100 + 1 methods on the new type?

You might want to take a look at a new Whidbey feature called Lightweight
CodeGen (LCG). LCG allows you to define new methods on the fly, without
needing to build & 'bake' a containing type (see
http://blogs.msdn.com/joelpob/archive/2004/03/31/105282.aspx for example
code).

LCG methods are akin to static methods, but you can always make the 'this'
explicit and just pass through as the first argument. That way you can
define your class on the fly (if you even need one), then add the methods
as needed.

--Peter
AddThis Social Bookmark Button