How to make Visual Studio forget a namespace? - visual-studio

I have a project called Geometry inside of which I had created a folder, and had been referencing that folder by its namespace, "project".Geometry.
I decided that I would rather simply name a class Geometry instead of the entire folder, so I moved all of the classes inside of the folder up a level.
When I named my new class "Geometry" I still get:
namespace "" already contains definition for "Geometry"
How can I make Visual Studio forget about that namespace?

You have to do more than just move the classes up a level from that folder. You must go into each of them and change the namespace associated with it.
code like this probably still exists in those classes:
namespace projectnamespace.Geometry
{
...
}

Related

Xamarin Android Binding Library Custom Namespace Not Recognized

I am creating a Xamarin Android binding library for an existing JAR that contains a single class and following the Xamarin binding library documentation, I am able to successfully rename the namespace using:
<attr path="/api/package[#name='com.company.blah']" name="managedName">Company.Blah</attr>
I also confirmed the namespace is changed in the generated class in the 'obj/Debug' folder:
namespace Company.Blah {
// Metadata.xml XPath class reference: path="/api/package[#name='com.company.blah']/class[#name='NativeClass']"
[global::Android.Runtime.Register ("com/sprylab/android/widget/TextureVideoView", DoNotGenerateAcw=true)]
public partial class NativeClass
{
...
}
}
I face two problems:
I am unable to reference NativeClass from a sample Android project. It's like to doesn't see the namespace at all. The binding project built successfully without errors.
If I remove the package namespace rename setting, it also builds successfully and I am then able to reference it in my sample project but it requires that I fully qualify the class name anywhere it is used:
private com.company.blah.NativeClass nativeClass;
I'm hoping if I can fix #1, then #2 will not show up again. If so, I'm also curious how you prevent fully qualified class names from showing up?
Going into the project settings of the binding library project and clearing the box to the right of the assembly name seemed to do the trick. Looking inside the csproj directly, it is the root namespace.

Visual studio 2010 - Class diagram with namespaces

How can I create class in specific folder (namespace) in my project, and see the classes grouped by there namespace?
1) Create a class in the appropriate folder with the option Add new Item.
2) Drop the class in to the class diagram.
http://social.msdn.microsoft.com/Forums/en-US/vsclassdesigner/thread/bebfa1a4-1930-4a56-b0fc-e15a238650ac/
When using Visual Studio Ultimate you can choose "Architecture" from the menu and generate a namespace diagram.
Once the diagram has rendered, you can expand the namespaces and other elements to show the classes they contain.
Note, specific folder != namespace. New files in given folders are defaulted to the namespace, but from experience, try not to rely on it when working in a team or with someone elses' code. ;-)

Visual Studio 2010: Folding auto-generated resources behind other files?

I have the following file: Foo.cs with a Foo class inside of it. I can't seem to find the right way to keep my resource files (resx) organized behind their respective files.
If I create a Foo.resx the resource file gets folded away nice and tidy behind the Foo.cs class. This, however, causes issues because the standard custom-tool that generates the code attempts to create another Foo class (Look at the Foo.Designer.cs: internal class Foo { ... }). If my Foo.cs file does not already contain a Foo class, this works fine (no naming collision).
To fix the naming collision I attempted to give it a custom namespace MyProj.Resources and use an alias to identify it: using R = MyProj.Resources.Foo; This still causes issues because the auto-generator has an issue creating a ResourceManager properly.
If I, instead, name it something along the lines of FooResx.resx it does not automatically get folded behind the Foo.cs file. Instead, it resides in the solution explorer right below it. Going into the MSBuild (.csproj) file and adding a <DependentUpon> tag, then Visual Studio neatly tucks away my FooResx.resx file. However, I can't actually use any of the resources from that file because the auto-generated code has an issue creating a ResourceManager properly.
Basically, is there any way to have the Resource files (resx) fold behind a cs file and still work properly using the standard Custom Tool (ResXFileCodeGenerator)?
I do realize that I can always place all my resources into a file within the properties folder: resources.resx. I'm trying to organize them better than that though.
Update:
I decided to manually edit the auto-generated code and make it partial. This allowed the code to compile, but I still ran into the same issue (Issue #2). It seems that if a resource file is folded behind (manually or automatically) another code file then the ResourceManager has trouble finding the *.resource file. This might be an issue I'll have to raise with Microsoft Connect about the ResXFileCodeGenerator tool. It needs to be able to locate the proper *.resource file when folded behind other files.
The solution could be to make your classes and your generated code partial classes - if you look at a .Designer.cs (from a System.Windows.Forms.Form for example) you will discover that it declares something like partial class Foo.
Foo.cs
public partial class Foo
{
}
Foo.Designer.cs
partial class Foo
{
}
Edit
It turns out that StronglyTypedResourceBuilder or PublicResXFileCodeGenerator insists on generating classes with either internal or public access modifier (it can be set in the .resx).
Setting ResXFileCodeGenerator as the CustomTool in the properties of your .resx still doesn't give you the behaviour you'd see in a generated .Desinger.cs of a Form.

How can I change the name of my project and have it reflect everywhere?

I created a project in Visual Studio 2010 but I mispelled the name well into development.
If I right click, and rename the project, it seems the changes aren't cascaded to folders and classes.
For example, if my project was named Foa and I added a class, the namespace would be:
namespace Foa
{
public class Bar
If I renamed the project to Foo, the class stays:
namespace Foa
{
public class bar
Is there a way to cascade that change?
Change the namespace in one spot and then Ctrl+. on it and choose the refactor option. This will change the namespace throughout.
Change the default namespace in the project properties, then use a refactor tool to change the namespaces. Resharper has a fix inconsistent namespaces tool that will do it but you can just use the visual studio refactor to do it manually.

Visual Studio and LINQ: placing the DBML file in separate directory in the project

My strategy was to keep the project's layout clean. Given that this is a datalayer project, and I'll have a class file for each concerned entity, I thought I would put the .dbml into its own directory. It turns out that locating your .dbml file within a subdirectory turns it into a lower level namespace of sorts.
This is a C# class library project.
Any hints where I could turn this functionality off, and get access to the LinqToSql dbml datacontext name without having to type the directory name to get access to the actual LinqToSql classes?
Turns out you need to find the properties of your DBML on the LinqToSql design canvas.
Right click -> Properties Find the Context Namespace.
Type in the namespace that you expect to have your DataContext classes available in.
Right below, find the Entity Namespace.
Do the same
Resharper Users: you have the option to view the properties of your DBML's subdirectory, and set the namespace attribute there.
If you go to the directory in your solution and view the properties of that directory you will see the attribute: Namespace provider = true
Set this to false
You can then go update the namespace to match the root namespace in your DBML file. Now whenever you add new dbml files in there, it will keep the namespace based on the root folder.

Resources