Reflection.Emit question

J

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?
 
P

Patrick Steele

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".
 
J

Jeff Johnson

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.
 

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