format ugly c# source code - c#

I found a C# game http://www.codeproject.com/KB/game/BattleField.aspx that does what I need to learn. The source code is poorly formatted and hard to follow. I used Visual Studio's format document, but the format is still bad. How do I reformat the source code to make it easer to read?

Visual Studio's format document should help.
That being said, if you want more elaborate reformatting, you'll need a third party tool. Resharper, for example, has the option of reformatting the code, but also of doing code cleanups (where small refactorings are done on the fly to make the code itself nicer).
They provide a temporary free trial - you can see if it works for your case and this project.

That codes requires refactoring and commenting. Visual Studio can help, but this work is not fully-automated as you understand :)

Related

.cs file stand alone no syntax error checking at all, no library auto detection for c#

I am not new to coding and I know I have never had this issue.
In Visual Studio if I just create a .cs file and check it's intellisense nothing works. auto complete for using. does not work, nor does simple syntax checking work (see image)
Am I crazy? Can someone else try this out, what am I missing?
NOTE this only happens when I just have a .cs file for an external script. I just need simple auto complete and syntax checking to work
A C# file is somewhat meaningless without a project file. Versions, references, etc… all depend upon having a build system. This is a somewhat pedantic truth, but it is how VS works. Pathologically, I could have a CS file Console.WriteLine(“Hello world!”); which in one project results in hello world, and in another results in the program formatting a disk.
Add the CS file to a project, or create one. If you frequently come across this issue in some unique use case, visual studio may not be the best editor for the job. VS Code or another more lightweight tool may be better suited.

made changes, compiled and regret

I made today few changes by ctrl+h to all the solution.
When I understood my mistakes I tried to undo it with ctrl-Z but the results were awful.
The question is : How can I reload the last compiled project before I had done this stupid move.
Lets say I want the solution as it was at yesterday.
Thanks for your help,
Eliran.
you can try decompiling the old binary with tools like dotPeek. But in general that is the reason why you use a source control system.
You cannot. Once saved, the changes are irreversible. That's the point of backups. There are tools to decompile your .NET executable, but as not all sourcecode is actually compiled into the executable (for example formatting and comments are not), you will never get your original code back.
You may want to look into source control software like Git, Subversion or Team Foundation Server to handle this problem properly next time.

Code snippet plugin

Are there any good code snippet plugins for visual studio? I want a plugin which can use a online snippet site (such as snipplr). It should be easy to both find and upload snippets.
You might consider snip2code plugin for VS2010.
It's interesting, I got it online...
Allows to search for your own snippets and public as well. Quick collector of code.
yes CodeKeep
There is http://www.int64.io.
It allows you to store snippets online. You can organize your snippets into "boards", give them tags, search (in near future), etc. It doesn't have a Visual Studio plugin yet, but it's coming.
Disclaimer: I'm the owner of http://www.int64.io
You might consider http://code.google.com/p/cr-codetweet/

Tool to automatically reformat whole C# source tree in VS2008?

I have inherited a large source tree, C#, Visual Studio 2008.
It has many quality issues, one of them is that the code is generally badly formatted.
I am looking for a tool, preferably a plugin for Visual Studio, that will go over the whole solution and apply the same basic formatting that Visual Studio itself applies when, for example, you close a curly brace around a block of code.
Any suggestions?
In vs2005, you can do Edit->Advanced->Format Document for a single file, which will (I believe) do what you're asking. I assume vs2008 has a similar function somewhere.
ok, so why not try a macro, if you want to do the entire solution, there is a vb example here
http://blogs.msdn.com/kevinpilchbisson/archive/2004/05/17/133371.aspx
it opens each file and applies the same formatting that VS does, but the macro will work across an entire solution (may not be that wise to run it if your solution is huge), beyond reflecting the internals of the format document code in VS and inling it into some sort of stream, this appears to be the easiest way to make use of what i consider to be a very useful feature in visual studio
ReSharper should do what you're looking for. Have a look at their Code Cleanup Feature. This can be applied to multiple files including the whole solution.
if you have already set your preferences in the vs editor options, you should be able to hit CTRL K, CTRL D which will tidy the code based upon your preferences
Here's the simple way (for me)...
I have my Visual Studio set to reformat on "Paste"
Tools | Options | Text Editor | C# | Formatting
**Automatically format on paste** (checked)
When I hit an ugly file, I do CTRL-A, CTRL-X, CTRL-V -- poof, instant format :)
Hope this helps.
Kevin

Which (third-party) debug visualizers for Visual Studio 2005/2008 do you use?

I guess this topic is often overseen, but is rather useful when debugging your code. Just today I have stumbled across this simple yet effective visualizer that visualizes images (it's on a german blog, but I guess the code content is self-explanatory):
link text
I would like to know which debug visualizers you use in your daily work with VS2005/2008.
I use Mole.
Mole was designed to not only allow
the developer to view objects or data,
but to also allow the developer to
drill into properties of those objects
and then edit them. Mole allows
unlimited drilling into objects and
sub-objects.
Also check out Xml Visualizer v.2 (http://codeplex.com/XmlVisualizer)
There was a sample on an MSDN blog for the Microsoft.Xna.Framework.Matrix, I think it was. I later made my own, but it was still good.
Since I do a lot with Graphics and GDI, I found the Graphic Debug Visualizer invaluable. The Bitmap Visualizer it is based on is good too, however I had to recompile it for Visual Studio 2008 (and change the references to the various VisualStudio extension dll's).

Categories

Resources