listing of Namespaces

  • Thread starter Thread starter Rizaan Jappie
  • Start date Start date
R

Rizaan Jappie

Hi, its Rizaan Jappie.

Is it possible to get a list of the root Namespaces on a pc as well as
the path to the specific Assembly using c#?

e.g.

Namespace Path
 
Rizaan Jappie said:
Hi, its Rizaan Jappie.

Is it possible to get a list of the root Namespaces on a pc as well as
the path to the specific Assembly using c#?

Not as you're thinking about it. Remember firstly that a namespace (such as
it exists) can span several assemblies -- I could make an assembly with a
class in System.Data if I wanted to.

Secondly, what about versions? The types within System.Data will appear
multiple times, once for each framework version.

What you can do is make a list of all namespaces within a particular
assembly, by enumerating the types contained within. I suppose you could
also enumerate all the assemblies on a PC and make a map of namespace to
assemblies (NB assemblies plural)....

.... but why? What are you trying to achieve?

Stu
 
I dont need all the Namespaces, just the root namespaces. What i am
trying to do is create a .csproj file through code. I am involved in
Code generation. So basically i want to be able to tick the namespaces
needed in a particular project and build up a VS.NET Project
file(.csproj) from there.
 
AFAIK, Reflection does not provided that information directly. You need to
load the Assembly, call GetExportedTypes and then build the list using
parsing Type.FullName and discarding repeaded namespaces

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
 
will it be possible to provide me with some code concerning your
suggestion...im kind of new to .net so some code would clear up alot of
issues..thanks
 
Hmmm... why?

I doubt it's worthwhile for the code generator to detect what is and isn't
being used by the code it's generating.

What I suggest is to go into Project|Add reference and grab all the
components you think you might ever use.

If you're generating code do you really need a project file? It seems to me
that only Visual Studio needs project files. Do you really need to edit your
generated code in VS?

I don't currently do any code generation, but I do write a lot of code (for
libraries) outside of VS and then use a make file to create my libraries.

Of course that still means I need to list the namespaces in the make file,
but that's a manual process anyway. Listing unused namespaces won't hurt or
bloat your code so you can add all you like.
 
you absolutly right. There is no need to automate the process of
selecting the appropriate Namespaces. I have convinced the necassary
members on my team that it is much quicker to add Namespaces in VS since
we have to use VS to edit the generated code anyway. Thanks
 
And I'll also point out that VS doesn't add references automatically as you
code either. It simply starts with the most commonly used ones. If you use a
class that's not in them it won't tell you until you compile that "you may be
missing a reference".
 
Back
Top