I have VS 2008 and csproj project (C# Library).
In properties of project, has an assembly name, and default namespace. Note: each class has a namespace.
Is it possible, in runtime, get the value of default namespace ??
My target is use resources, and I need default namespace's value:
Assembly assembly = Assembly.GetExecutingAssembly();
//foreach (string resourceName in assembly.GetManifestResourceNames()){}
Stream syntaxModeStream = assembly.GetManifestResourceStream(pathToResources
+ ".SyntaxModes.xml");
Update:
Pieter said I can't. Default namespace don't stored in assembly
var resource = assembly.GetManifestResourceNames().Single(p => p.EndsWith(".SyntaxModes.Xml"))
where is the default namespace stored ??
Only can I read using Addins Visual Studio (DTE object) ??
I wrote an extension method for Assembly that just finds the resource by its filename within the included resources:
then you just call like so:
Not 100% sure it's what you're looking for but you can get the namespace using :
I came to this page in search of confirmation that I hadn't overlooked anything in my search for an assembly property that corresponds to the root namespace entered into the main Visual Studio project property page of a Windows application.
Since I had an idea for solving the problem for the use case that brought me to this page, and I anticipate that at least a few others would benefit from my discovery, I kept the page open while I conducted my research.
As I suspected, it is relatively easy to associate a meaningful, not to mention ultra useful, namespace with the entry assembly. The following very long expression returns the namespace of the Program class defined in the Program.cs module of any Windows application.
The following C# statement, executed from anywhere in the application domain, even through a method call that reaches into a DLL, reports the name of the entry point routine and its namespace.
For a console mode program called OperatingParameters_Demo.exe, whose root namespace is OperatingParameters_Demo, the above statement yields the following output.
The practical use of this expression is that you can use it to construct the absolute (fully qualified) name of the Properties.Settings and Properties.Resources namespaces of the entry assembly.
I am almost finished with an application that takes advantage of this technique to display parameter names that are stored in resource strings based on resource names that are derived from the parameter's internal name. This lies at the heart of the generic program parameter processing library that the tool demonstrates.
This demonstration project began when I started work on a programmer's tool to import C/C++ header files into a project directory, so that I can deploy a self-contained project into GitHub, even though the master copies of the headers are stored elsewhere because they are shared by dozens of projects. As its parameter parsing engine neared completion, I realized that I was incredibly close to having the generic operating parameter parser and backing store that I have wanted for many years. The C/C++ header importer will eventually be published. However, at the moment, only its parsing engine is finished. Since it is useful on its own, I intend to publish it first. Stay tuned to The Code Project and GitHub.
You can't.
The default namespace isn't stored anywhere within the assembly. It's just a project setting of Visual Studio.
What I tend to do is use the name of the assembly:
Assembly.GetName().Name
. The problem with this is that it only works if the assembly name has not been changed.For your specific issue, you can use
assembly.GetManifestResourceNames()
and do some tests over those names, e.g.: