Fast easy refactoring in visual studio - c#

I have a large project that is quite a mess. There's God classes, poor variable naming, poor indentation and spacing...among other issues.
I'm looking for a quick and easy way to make marketable improvements to such a project. In Visual Studio 2010 CTRL + K and CTRL + D gives me fast code cleanup. Organize usings takes out unused namespaces. But, both only seem to work on 1 page. Can I apply these changes to a project? Are there any similar cleanup techniques or free and reliable 3rd party addons?

Try out Resharper-- it can do what you're looking for.

One third party extension that I use that is free is DevExpress' Coderush Xpress (For C# and VB), which is the free edition of their full product. The great thing about this is that the express edition still lets you add CodeRush plugins to it (in addition to several project-wide refactoring options), which opens you up to a ton more options than just the Visual Studio Plugins.
Here is a huge list of the plugins available for CR Xpress.

I have been using Visual Assist X for quite some time, and I found it very useful. It is not free, and it may not automate the sweeping changes you seem to be looking for, but it makes simple refactoring much easier.
P.S. I have been using it for C++, not C#. But if anything, I would assume that it would have more capabilities for C#.

Related

WinForms - Any way to convert UI of Visual C++ project to Visual C#?

I'm now done with a .NET WinForms project in C++. I'm using Visual Studio 2013 Express Edition.
So from my experience so far and after a little bit of research, I find C# to be more clean, easy and more popular way to make the best out of the .NET framework. I found many straight forward references online for many problems in C#, which I had to struggle to achieve in C++. Also, C# gives me faster builds and it has pretty easy resource management.
So for the above reasons, I'd really like to port my current C++ project to C#. I know I'll have to translate the logical code, but is there a way to take atleast my GUI, ie My Forms directly into the C#'s designer? Or am I only left with the option of Designing the whole UI again from scratch?
Any help will be very appreciated, Thanks a lot for taking your precious time for me.
You could use a decompiler like ILSpy or Reflector. You should be able to decompile your assemblies in C#. With little effort or much, depends how big your project is, you could switch from Managed C++ to C#. Some Decompiler Addins allows to completly write the assembly to disk.
But you lose information with this approach. Basically comments, sometimes you gain goto's, get some compiler generated stuff and so on. But with the InitializeComponent() Method you should be fine.

Does Visual Studio for C# have these Eclipse for Java features?

So far I use to develop in Java. Java is multi-platform (now works on Android!), has a very powerfull VM and is open, well behaved, etc. But is also old and seems to be stopped on time in terms of language features. Scala and Gosu are nice replacements, but I don't like Scala syntax and Gosu is very immature and unlike to win from Scala. All this makes me think about moving to C# at least for web development! Phew!
One thing that is quite important to me is IDE support. Right now I use Eclipse for Java, and my favorite features are these (most important first, somewhat):
Full code navigation (call hierarchy, show variable reads & writes, inherited members).
Incremental compilation (which means fast compilation).
Many kinds of errors are detected and underlined before compilation.
Many intelligent quick-fixes (can fix/write many code for you and quickly rename elements and refactor references).
Intelligent and configurable code completion. Display hints even for unimported packages/classes.
Over 15 kinds of refactorings, all of them very useful.
Over 15 options of source generation (add unimplemented methods, generate getters and setter, generate delegates).
Configurable code formatter, even for code fragments (select code then format).
Debugger supports hot code replacement and "Drop to Frame" so I can go back an check other things without full program startup.
Code cleanups (remove unnecessary parenthesis, remove unnecessary "this" references, etc).
Very decent, autonomous and seamless CVS integration, with integrated file comparison and computer-aided merge.
Very nice tools for web development (server deployment, JavaScript and HTML editor with formatter).
Tons of plugins (code coverage analyser, memory dump analyser, eGIT).
Which of these features are available in Visual Studio for C#/ASP.NET? If I can get some by adding a cheap plugin, please tell.
Well, I like Visual Studio a lot more than Eclipse. I have only used Eclipse for minimal Java programming and Action Script. Visual Studio can do every thing you listed and if you combine it with a paid plugin like Resharper or CodeRush, you get a lot more. Why don't you download Visual Studio Express and play around with it? That would be much better than getting an answer from a very biased C# dev.
VS2010 with the addition of ReSharper has most of these things. I can't speak to CVS, but it does have fine SVN integration.
I started using VS about six months ago after a few years of Eclipse, and it works pretty well.
Nothing is cheap in the VS world compared to Eclipse.

Are Visual Studio Express products really only for "hobbyists, students and novices"?

I have used Visual Studio Professional 2008, and have been testing the free C# Express 2010 version recently. In general I'm amazed at how good it is for free, and how many of the full VS features it has. I'm thinking of using it for a commercial program and I know the license allows for that, it's just the description of it being for "non-professional developers like hobbyists, students and novice developers" concerns me a bit.
What I'm interested in knowing is what is stopping it being 'professional', that is:
Have you evaluated the express edition, and found a specific useful feature lacking that stopped you from using it ? Or did you initially use the express versions, but upgraded to full VS because of a feature lacking ? If so, what was that feature ?
I've searched for similar questions and found lists of differences between the full VS and express versions, but I'm more interested in knowing peoples personal experiences with it. It seems like many of the extra features in VS target developers working in large teams, so I'm mainly interested in hearing from either solo or small team developers where it seems like there's less compelling reasons to upgrade.
The limitations I've personally encountered are:
Extensions not being supported, though I can still use DotTrace, NUnit and an obfuscator outside of the VS integration, albeit it's a bit less convenient.
Limited refactoring, although the "Rename" and "Extract Method" are still there and I think they're the most useful. Edit: Not having 'Encapsulate Field' in Express used to be annoying though, though the introduction of automatic getters and setters has pretty much canceled that out I think.
More limited debugging for multi-threaded apps.
Edit: Another is that you can't easily switch between targeting "Any CPU/x86/x64" in Express like you can in VS. It is possible, but needs manually editing your project file to do so.
But the pluses seem to outweigh the minuses so far. Is there anything you found was a deal-breaker for you ?
Update: To come back to this a couple of months later, and after releasing a product built with the Express version, it is indeed possible to program professionally with the Express versions. The limitations within the program itself are pretty minor and can be worked around, but I've increasingly come to realise it's really the "extensions not supported" one that's the (only) major drawback. No Resharper, CodeRush or the like, and no source control, profiling, database explorer or unit testing and the like within VS itself. It's more of a productivity drag than a deal breaker, but it is annoying to come across a cool looking VS extension only to see that "Not supported in Express versions" notice.
If anyone else is in the same situation, I'd evaluate the extensions you use (or might be planning to use) first and see how important they are to you. Express is fine if you don't use any extensions or could live without them without a significant drop in productivity, otherwise stick with the Professional version.
I've used express for 5 years, it has everything you need to produce professional projects. There's one important feature that's missing, which is the extensible Database Explorer, e.g. if you need to generate an Entity Framework model from a MySQL database. But for that I use Visual Studio Shell (also free). For other stuff such as unit testing and source control I use other tools. You really don't need Visual Studio to have everything you need to manage a software project.
No add-ins => No ReSharper => No dice.
The biggest problem with the Express version is you don't have any source control. You can't professionally work without it, even if you are a lone freelancer. Keeping a change history on a project is vital when you mess something up and want to go to a previous version or simply want to compare different revisions.
Also I think in Express you can't have web and desktop applications in the same solution, or do other types of combination of projects. I'm not really sure about this one, because I don't use Express (for the first reason :))
Other answers have covert the fact that it can very well be enough, but if you are more than a hobbyists, students or novices, just get enrolled into the Microsoft BizSpark program.
You get all the tools for free (Visual Studio Ultimate, Team Foundation Server, All Windows Versions etc.) and you don't even need to be a company. Enrollment is super easy and uncomplicated.
The only requirements are (taken from the homepage):
You develop software
Privately held
Less than 3 years in business
< 1mio $ per year
This is not an ad. We have been very happy with the program and got access to everything we needed. Just wanted to let people know it existed.
Additional info:
You can be member of this program for 3 years
When you leave the program you have to pay a 200$ fee, its made for startups afterall
I had been using VS Express for several years but I recently upgraded to VS Ultimate. There is nothing that you cannot do in Express, but the integration of features in the full product makes everything more convenient.
When you have source control, unit tests, performance/code analysis, installers all in the same solution, it saves a lot of time and hassle jumping between different programs. Also one big issue for me was not being able to mix features that are spread across the different Express editions, such as mixing ASP.NET with WinForms, or even VB.NET with C#.
I got a lot of use out of Express, it's a great product, but I was very happy the day I got to uninstall ten programs and replace them with one.
The pros:
Absolutely free
Has enought functinality for you to develop commercial products (you know the saying: you need 20% of anything to get 80% done). I developed and deployed a wp7 (windows phone 7) app with the express edition and it was a pleasant experience.
The cons:
No integration with source control. I use svn for my projects and i have to use tortoise svn outside of vs to manage the code. Its a minor annoyance, not a deal breaker.
Can't develop web/desktop/mobile in the same solution. Its easier to have them all in the same project when you have a common dll for your business logic. Unfortunately with express edition you will end up using copy/paste for moving dlls that are common between projects. Again it's a minor annoyance, not a deal breaker.
Professional is not the big step up here - Ultimate is. VS2010 Ultimate, for example, comes with bunches of profilers and that kind of thing. They give Professional away to any old student, for example.
There's only one plus: the cost. Every other difference is a minus (or at best reduces the cost of the minimum useful system). That means that, if the extra features are worth the money, buy the higher-end version.
The free lower-end version is great for (as they say) students, hobbyists, and novices. Students often don't have much money, and hobbyists and novices often don't want to spend all that much money on their hobbies and introductions.
However, a software professional is making money writing software, and presumably will make more money if he or she becomes more efficient. Assuming our professional is making decent money, the cost of an upper-end version of VS isn't large compared to revenues, and if it leads to even modest productivity increases it's worth it.
When you're doing something for money, don't try to do things too much on the cheap. Taking more time and inconvenience to do things will cost real money in that case, and avoiding it is worth real money.
Microsoft's marketing approach to these Express editions may be is to introduce Visual studio flavors to users (any user). Later, bring them on board with more powerful versions. Also, Express editions allows you to write code anywhere without getting worried about licensing part. You can use them to try out your test bed projects, community projects etc. I must re-iterate again that free licensing is the biggest draw towards Express editions
The only substantive differences I've found are the integration of code control and the ability to create heterogeneous projects. The first is not a major issue if you are the only developer. With the Express versions, You can use whatever code control mechanism you like, just not built in.
The second is only an issue if you want to develop using some combination of C++, C# or VB in the same project. You need at least VS2010 Professional to do that. Given the extensive features in C#, the absolute need to use C++ or VB with it in the same project is highly unlikely. However, those situations exist if you need C++ in a C# project for some low level API or have a legacy VB system and need some feature from C# or C++ that is just too difficult to manage in VB.
As a friend who built racing engines once observed: Speed costs money. How fast do you want to go? Express is free, the others can be pricey, although the price for VS2010 Professional just plummeted with the advent of VS2012.

Visual Studio add-in for C#-development

I want to write my first Visual Studio 2010 add-in. My aim is to create an add-in that helps to automatically generate code for things like:
implement superclass constructors
create delegation methods for composed object
etc.
Of course, in order to know what to generate, my add-in must have a knowledge of the code-file the user is going to insert generated code into. (classes, base-classes ...)
My first thought was to use a C#-parser. Is this the right way to go? Isn't there any .NET-Framework part, COM-Object or whatever "built-in"?
Thank you in advance.
P.S: Is noticed that CSharpCodeProvider's class Parse() method has not been implemented by Microsoft yet. -_-
You can get a lot of info from the MS Visual Studio Extensibility site. This post from the Visual Studio blog may also get you started with dealing with the in memory code file.
You could start by looking at EnvDTE, which will help you browse through project files and code trees already parsed and analyzed by Visual Studio, as well as modifying them. EnvDTE is pretty basic and error-prone (for the few times I used it). Finding good in-depth tutorials is also difficult.
If you're trying to implement such features yourself, good luck, it's definitely doable but the learning curve might be quite steep. Otherwise, you could have a look at ReSharper which already implements the features you're trying to code (and much more). Plus it also has a very well designed API compared to EnvDTE (although not very well documented), allowing to use its internal C# parser / analyzer.

ReSharper 5.0 VS CodeRush 10.1 - Specific Feature Comparison

I'm deciding between ReSharper 5.0 VS CodeRush 10.1. I've seen a lot of questions that target which one is better/faster than the other. For Example, ReSharper may be a little slower than CodeRush when working with large projects. What I am looking for is a list of which features are completely, outright missing in the opponent.
An example would be that ReSharper has an intellisense replacement, which CodeRush leaves to VisualStudio.
What features does one have that the other is missing - assuming performance/speed and learning curve is a non-issue?
(I'm ReSharper Product Manager, take with care)
For me it is not specific features that make most sense here, you can make up any numbers on comparison charts by categorizing things, e.g. you can count formatting actions as refactorings. Also some missing features here and there can be complimented with other plugins - being them within tool's ecosystem or VS ecosystem.
What I really find important for any tool of this kind is deep and accurate code understanding. Some tools, unfortunately, are not that accurate. Every product has bugs and issues, of course, but being not able to accurately resolve symbols is show-stopper for me. May be not for other people, who value fast typing over accurate analysis and refactoring. Other tools in this area cannot even parse C# code sometimes, not to say about resolving generic overloaded methods with lambdas and correctly supporting LINQ patterns.
As for complete, direct and independent feature list comparison, I don't think there is one. I believe every product has comparison chart with Visual Studio (ReSharper has), so you can combine them, and then clarify specific points with the community and users of corresponding products.
I am personally using and loving both, DevExpress CodeRush Express for VS (free) and ReSharper (open source license).
http://www.devexpress.com/Products/Visual_Studio_Add-in/CodeRushX/
http://www.jetbrains.com/resharper/buy/opensource_license.html
Honestly speaking I want both, though they do have some overlaps such as refactoring, code analysis. But they do have a lot of unique features, such as structure highlight (CR). And at some extent installing both consumes more system resources. However, the benefits from both products are huge.
Always use a powerful machine (or machines) as your development environment, and it can overcome a lot of pains in the near future :)
Cards on Table: I'm a huge CodeRush fan and a member of DX-Squad (Which means I help out on the DX forums)
As you might imagine, I use CodeRush quite a bit and I have a reasonably good knowledge on what is, and what isn't possible using the current DX toolset. I think however that there are few who are particularly well versed in both products
As for what might be missing from each. Typically this doesn't bother me... If I need something not supplied with CodeRush, I tend to build it myself :)
The DXCore (free framework on which CodeRush and CodeRush XPress are built) makes this very easy. Feel free to head over to our community site and take a look.

Categories