Generating classes in Visual Studio. Advice needed on approach - c#

Not sure the best way to achieve this and I would like your input.
I would like to generate a View - a ViewModel and another couple of classes.
I don't want to generate a project but just some classes.
Implementing the IWizard can you generate more than one class at one time?
Ideally I would like the user to click on a template in visual studio ,input some names etc... and generate this 4-5 classes for them.
What is the best to achieve this? Any links or suggestions on approach?
Thanks.

I would suggest using a T4 template. The engine's built right in to Visual Studio 2010, and there's a good free editor you can get through the Extension Manager (Tools > Extension Manager > Online > Search for "tangible T4").
As for how to code the templates, here's a good blog post on it which will get you started:
http://www.olegsych.com/2007/12/text-template-transformation-toolkit/
There's some info in MSDN too: http://msdn.microsoft.com/en-us/library/bb126445.aspx

Related

How to override MVC "Add Controller"

I am trying to create a visual studio extension to create a new wizard or override the current "Add Controller".
I Have the extension made and everything set up, but i cant seem to use any code generators in .net framework, i tried the System.Web.Razor.Generator and the Microsoft.AspNet.Scaffolding.
Does anyone done this before?
Thanks in advance
This should let you add your own template to the wizard so you can easily add replicated templates.
You can also add or edit views as well
So in this article we have seen how to modify the existing code or
adding our own custom code generation for scaffolding column for
generating a Controller class and view in ASP.Net MVC3 using T4 Code
Generation.
https://www.c-sharpcorner.com/UploadFile/b19d5a/modifying-or-adding-the-default-code-generationscaffolding/

Updating the namespace automatically in Visual Studio 2015/ C#

I am doing some clean up/ restructuring on my code (C#) were I move my classes in the tree structure. I am looking for a way to update all namespaces to the default ones (like projectname.rootFolder.ChildFolder).
I know that there are some ways to do it one by one like in this old post but I am looking for a clean simple update way. I wish there was something like "right clicking on the folder and clicking on update namespace!" but there is not.
Anyone knows any add-on/ easy way to do it?
Resharper is a tool to work on legacy code. Try to use this tool.
Right click on the folder> go to refactor and then select adjust Namespaces

Visual Studio -- Expanded Intellisense View (Like a mapped treeview)

When you are typing with Intellisense and it shows you the parameters within a class, you can select a parameter and keep going until you arrive at the base level. When you are debugging, Visual Studio lets you stop on objects and inspect all of the parameters or fields within them.
Is there a way to build a treeview or diagram of all of the class parameters? I have a large class that included ton of sub objects and properties and I would like to build a view of all of its properties.
If you are just talking about being able to visualize your classes (through Visual Studio, not actually building a hierarchy through code) you can do it like this: In Visual Studio, click View - Class View. This will give you a tree view of your classes.
If you click View - Object Browser you will see a tree view of classes in other assemblies too, not just your classes.
EDIT
I think you are looking for something like the Solution Navigator in the Productivity Power Tools Visual Studio extension. Click Tools - Extension Manager - Online Gallery. Search for Productivity Power Tools and install it. You will then see an option under the View menu for the Solution Navigator.
If you want control over the way variable values are displayed during Visual Studio debugging sessions, you can apply the DebuggerDisplay attribute to the class of interest. You can alternatively overload ToString() on the class of interest to print the info you desire, assuming that this behavior would not conflict with any other requirements you may have.

Generate control C# code from NIB's and insert into MonoTouch's designer.cs files - Visual Studio style

I've begun using MonoTouch 5.x. I feel like I'm fighting NIB's to use inheritance.
I want to use inheritance. I want to use a designer to make my views. I want it all.
So I've been searching for a tool that generates xxx.designer.cs files like VS does it: inserting the controls in code on the fly when designing using IB. Reducing NIB's to a design-time feature.
As far as I can tell, this is the cleanest approach with the best performance that allows me to go full C#, "visual inheritance", etc.
Does anyone know of such an initiative? In any form or shape?
Thanks.
In Microsoft Visual Studio you are able to write an implementation of IVsSingleFileGenerator.
Which is then used as custom tool to generate files at design time.
Maybe there is a similar feature in monodevelop.

How to specify template class visibility for a T4 preprocessed template?

I have started adding some preprocessed T4 templates to a VS2010 C# library project. They are implementation details only, and I would prefer to not have them exposed on the library's API. I have not found a way to set the template's generated class visibility to 'internal'.
Is there a way? (If there is, I assume it will be something obvious that I have missed)
Thanks in advance,
/AI/
VS2012 has visibility="internal" on template.
Aethon,
Unfortunately there is no way to do this today short of post-processing the generated code in some fashion.
I'm looking at adding this for a future release of Visual Studio. If you wanted to log a Connect issue for this, that would be helpful.

Categories

Resources