views:

145

answers:

1

I have an C# ASP.NET Web Application Project where all the pages are in the global/default/top-level namespace. (I have no explicit namespace declarations. And when I look at my compiled web application's DLL in Red Gate's .NET Reflector, I can verify that all the classes are in the top-level .NET namespace.) Is there any good, automated way to move all the pages and custom controls into a new namespace, say "MyWebApplication"? Ideally it'd be nice to do it with just Visual Studio, but I'd be open to considering a commercial refactoring tool if necessary.

I thought maybe by setting the "Default namespace" property in the project's Application properties I could get the compiler to implicitly put all pages into the specified namespace, but this appears not to be the case; this "Default namespace" setting seems to make Visual Studio insert explicit namespace declarations into new pages, rather than implicitly affecting the namespace of any existing pages.

If it matters, my immediate motivation here is to try to run a static analysis tool (CAT.NET) on my web application; the tool seems to have a quirk or two with code in the global namespace.

+1  A: 

Chris it may look silly as you are ready to pay for the refactoring tool to do it. But consider this:

The namespace is declared in the code-behind file by default as the project/application name. So if you project name is MyWeb the default namespace will be

namespace MyWeb
{

   public partical class MyWebPage....

Now this is refered in ASPX page as follows:

 <%Page ... CodeBehind="MyWebPage.aspx.cs" Inherits="MyWeb.MyWebPage"

You only need to change these two things to put into effect the namespace migration. And frankly this can be achieved using Find/Replace dialog. Please make a copy of your complete solution and try it!!

Cheers

TheVillageIdiot
I think he's saying that none of his pages have a namespace, which is what Visual Studio does by default for a Website Project. Find/Replace won't work because there are no namespaces defined.
Nathan Taylor