Home All Groups Group Topic Archive Search About

Reflection.Emit question

Author
12 Oct 2006 9:31 PM
Jeff Johnson
When creating types with Reflection.Emit, is it possible to define
namespaces? I've just begun to delve into this functionality and I saved one
of my dynamic assemblies to disk. Then I referenced it in a project and
viewed it in the object browser. The types I created were directly
underneath the assembly icon in the tree view as opposed to there being a
namespace icon.

Ultimately, I'm trying to reference a type I've created in this dynamic
assembly by specifying its type name as a string and using...oh, damn. I
just remembered reading about Type.GetType() and how it can't return types
from dynamic assemblies that haven't been saved to disk. Crap.

Well, just for curiosity's sake, does anyone know the answer to the first
question?

Author
12 Oct 2006 11:24 PM
Patrick Steele
In article <eKYYLXk7GHA.***@TK2MSFTNGP03.phx.gbl>, i.get@enough.spam
says...
> When creating types with Reflection.Emit, is it possible to define
> namespaces? I've just begun to delve into this functionality and I saved one
> of my dynamic assemblies to disk. Then I referenced it in a project and
> viewed it in the object browser. The types I created were directly
> underneath the assembly icon in the tree view as opposed to there being a
> namespace icon.

I think you just create the entire class name with a namespace.  So if
you wanted a namespace called "JJ" and a class called "Auto", you'd emit
a class called "JJ.Auto".

Author
13 Oct 2006 2:11 PM
Jeff Johnson
Show quote
"Patrick Steele" <patr***@mvps.org> wrote in message
news:MPG.1f9898b66c7f0c269896af@msnews.microsoft.com...

>> When creating types with Reflection.Emit, is it possible to define
>> namespaces? I've just begun to delve into this functionality and I saved
>> one
>> of my dynamic assemblies to disk. Then I referenced it in a project and
>> viewed it in the object browser. The types I created were directly
>> underneath the assembly icon in the tree view as opposed to there being a
>> namespace icon.
>
> I think you just create the entire class name with a namespace.  So if
> you wanted a namespace called "JJ" and a class called "Auto", you'd emit
> a class called "JJ.Auto".

Bingo! Worked perfectly. I never would have thought of such a simple thing.

AddThis Social Bookmark Button