Malfunction Posted April 29, 2004 Posted April 29, 2004 One might think there should be a VS.Net forum or a general IDE-forum ;) I'm wondering if there's a way to organize the classes in the project explorer. So far I have 20 classes (basic classes, controls, forms and interfaces) and there are many more to come. Is it possible to create folders so I can sort all interfaces, forms that represent dialogs etc. Do I have to put the classes in "physical" subdirs to sort them or is there some way to just change the view of the explorer? thx Quote Debug me...
Denaes Posted April 29, 2004 Posted April 29, 2004 One might think there should be a VS.Net forum or a general IDE-forum ;) I'm wondering if there's a way to organize the classes in the project explorer. So far I have 20 classes (basic classes, controls, forms and interfaces) and there are many more to come. Is it possible to create folders so I can sort all interfaces, forms that represent dialogs etc. Do I have to put the classes in "physical" subdirs to sort them or is there some way to just change the view of the explorer? thx Namespaces in the code. I see names that align with the namespace to be VERY common with professional .dlls. Example off of my c1 components. c1.win.c1flexgrid.classic.dll Organized by company, winforms/webforms, major class/control name, subclass/control name, etc, etc. The c1.win.c1flexgrid.classic actually is what you need to type to get to flexgrid classic methods/properties unless you import the namespace c1.win.c1flexgrid into your form Hope this helps a little. Quote
*Experts* Nerseus Posted April 30, 2004 *Experts* Posted April 30, 2004 There are two basic ways to organize your code, depending on what view you like in Visual Studio. I prefer the Solution Explorer, which shows files and folders. For that, you can create folders in the project (which become folders on your harddrive and folders in Visual SourceSafe if you use it). New classes added to that folder will have a default namespace that includes the folder name (best to use folder names with no spaces). For example: MySolution1 - MyProject1 (the project) \UI\ - frmMain.cs - frmSplash.cs - frmMyDialog.cs \Components\ - mainain.cs - splash.cs - mydialog.cs \XSD\ - dialog.xsd In this sample, the UI folder contains the forms. I like to have each form's UI code in the form's class, but all "business" code in a separate file. I keep these "component" classes in a "Components" folder. If your project has other file types, such as typed Datasets or similar, you can make separate folders for them. You can obviously create as many folders as you like. Namespaces: In the above example, the namespace for the class "frmMain" in file frmMain.cs would likely be "MyProject1.UI.frmMain". The corresponding component class would be "MyProject1.Components.main". The new Visual Studio supports "partial" classes, which means you can split one class among many files. With partial classes it might be possible to keep the UI and "business" code in two files, but they're combined into one class when compiled. I haven't played with that too much to see how it works out. In "Class View" (as opposed to Solution Explorer), you can get a hierarchy of the classes grouped by namespace. The above structure would look very similar. Using either view, putting namespaces in your classes is a Key. The namespaces should generally follow the pattern of files on the hard drive unless there's a good reason not to. So if you have frmMain.cs in the root folder and want to move it to a "UI" or "Main" folder, you'd have to modify the code from something like: using System; namespace MyProject1 { public class frmMain { } } to something like: using System; namespace MyProject1.UI { public class frmMain { } } -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.