I'm new to Xamarin framework, and as I created a new Android Application I noticed the MainActivity.cs class located in the root of the project. I'm also new to C# so I don't know if all files are supposed to be on the root, but if not, will there be any issue if I organise my classes in packages/folders?
There is no problem with organizing classes into folders. Namespaces are much more important than the physical location of the files, but it's good practice to have your namespaces reflect the folder hierarchy.
For example, if you create an Activies folder on the root and move MainActivity into that, the namespace in your MainActivity.cs file should be YourAppName.Activities.
When you add new files into an existing folder, this will be done for you, but moving existing files into a folder will require a manual refactor of the file's namespace.
Unlike Java in C# you are not required to place a class in any particular file, indeed you can place a class in multiple files (this happens when you use Xaml) or more than one class in one file.
That said I would recommend you place each class in a file named after it and that you, in general, make a folder for each namespace. However I have seen some mysterious crashes and "could not find class that actually where there" related to this, so you may have to skip that if you find weird issues with Xamarin Studio.
Related
I created a simple standalone SQL-table-to-class generator as a WPF application.
When I save files (e.g. a .cs class file) from that application into the directory structure of a separate web application I'm working on, it is of course not added to the solution. I have to manually add it in.
Is there a way I can automatically tag it/flag it or whatever, to be included in the web application solution?
The only solution I know of is to manually modify the .proj file and add a content include directive for the directories you want with a wildcard.
<Content Include="SomeDirectory\*" />
You will need to do this for each directory and it isn't recursive. The major down-side though, is that you must reload the project for it to pick up new files.
Personally, I consider this to be a bit of hack and would never use it in a serious project.
I really love using Kobold2d - it makes many aspects of Cocos2d development simpler.
But a major annoyance I've found is that since all new projects are contained within the Kobold2d workspace, if I try to recycle a class name, ie use the same class name for different projects ("GameManager", "GameLayer", "MainMenu", etc), performing a cmd+click (frequently how I navigate my codebase) will take me to the original instance of the class in the workspace... Not the current project.
I've many times found myself making code changes before realizing I was working on the other project's version of the file.
Is there any way to change this behavior? So far I've just been deleting the orginal project from the workspace, cleaning, and reindexing all the files.
This doesn't seem like an efficient workflow though and I doubt it's the way Steffen Itterheim #gaminghorror intended..
Anyone have an idea how to make sure clicking on a class name first maps to a file in the current project?
I have a .NET project in VS 2010 that has grown to consist of a large number of forms, classes and other code files. I am liking the idea of grouping some of these files into subfolders, but when I attempt to move them, a namespace nightmare begins.
Upon moving a form to a subfolder, Resharper complains that the namespace does not correspond to file location, and suggests a namespace change from "MyNamespace" to "MyNamespace.Subfolder"
If I do this, of course all references to the form then also need to be updated.
Should I ignore the namespace suggestion, or is there some better way to organize code files after-the-fact?
If you are using Resharper (which you appear to be), it has a feature for sorting this out for you.
You should move the file, and then right-click the project and select [Refactor]->[Adjust Namespaces] - it should then fix all the namespaces in that project for you.
This allows you to move multiple files and then fix the namespaces for them all in one go (or at least per project)
I've been playing around with the structure of my project, and I'd like to reset the namespaces of my classes to what the default would be. That is, the default namespace for the project, plus each of the folders in the hierarchy.
It's not as simple as just find + replace, since I've both added and renamed some folders, and files from some namespaces were split into multiple other namespaces. I'm using VS 2010.
Unfortunately, I think this is not something you can do natively with Visual Studio.
Resharper, however, appears to have exactly what you're looking for:
http://www.jetbrains.com/resharper/features/code_refactoring.html#Adjust_Namespaces
I have been using the Codesmith framework NetTiers to generate a DAL etc., into a folder called, say, 'NetTiers', outside my main project's folder, and referencing the DLLs within that folder from my main project.
I've started using the Plinqo framework, and want to use the generated files from that framework within the same project as the one I'm using with NetTiers. (The reason I'm using both frameworks is that I want to get/learn the newer LINQ goodness from Plinqo, yet also have the familiar NetTiers code DAL, BLL syntax available, for compatibility.)
My question is: what's the best Visual Studio solution and file structure to use when using Codesmith templates like these? Should the frameworks' generated code be contained outside the main project and added as projects to the overall solution? Or should each template's generated code have its own solution? Should the generated files be within the main project's file structure?
I've tried combinations of each of these, and they each have their pros and cons. I'd like to know if there's a tried and tested pattern.
When it comes to .netTiers, I always compile the generated solution and add the assemblies as references to my project. This makes it much easier to upgrade/diff and regen.
However, there are going to be some cases where you would want to add your custom logic so keep this in mind.
Thanks
-Blake Niemyjski
I tend to just keep the .csp and the generated folder outside of my main app's folder. When adding a reference Visual Studio copies in the .DLLs from the built generated code. All of the generated projects sit under a main folder such as D:\CodeSmith Projects\
If you want to version control the .csp file it might be beneficial to move it in with the rest of your version controlled app files to tie it all together.
We put the generated projects inside our solution. In fact on my current project I generated the nettiers files to the location that I wanted the files to be, and Started adding my own project files to that...But we have always kept the files in the solution, that way if i need to add something to the code in the concrete classes I can do it without having to open a whole new project.
We have tried both scenarios. We settled for including the assemblies in a dependencies folder, which was shared by multiple projects.
We had problems with TFS when the projects were included in the solution. the downside, is that you can't so easily step into the .NetTiers generated code when debugging, though after a while you get used to this, and accept that whatever is in .NetTiers stays within .NetTiers!