What are the most useful (custom) code snippets for C#? [closed] - c#

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
What are the best code snippets for C#? (using visual studio) VB has a lot that are pre-defined, but there are only a handful for C#. Do you have any really useful ones for C#?
Anyone want to post a good custom one you created yourself?
Anyone?... Bueller?

My absolute favorite is cw.

There's plenty of code snippets within Visual Studio for basic programming structure but I wouldn't necessarily rate one higher than another.
I would definitely say the best ones are the custom snippets you define yourself to accomplish more specific tasks that you may find yourself using on a regular basis. Definitely a big time saver.
A fairly basic intro to creating custom snippets can be found at http://www.15seconds.com/issue/080724.htm to help with this.

Microsoft have released a whole bunch of C# snippets that bring it up to parity with the ones for Visual Basic. You can download them here:
http://msdn.microsoft.com/en-us/library/z41h7fat.aspx

These are the ones I use daily.
prop
try
if
else
for
foreach
mbox - Message box stub
The ability to role your own. I have one for Property that are saved in the view state, methods a custom class example.

I had a few on my old blog:
testmethod Code Snippet
onevent Code Snippet
cleantestresults Code Snippet
astype Code Snippet
I also have an argnull code snippet that inserts a Guard Clause that checks an argument for null and throws an ArgumentNullException, but I haven't gotten around to post that yet.

prop and exception are my favorites.

I just started a blog, where I document short solutions in C# (code snippets) that I came up with and might prove useful to other coders.
http://thorstenlorenz.blogspot.com/
So far I have mostly blogged about extension methods and generics.
So have a look and tell me what you think.

Just to update an older thread... here's a link for Visual Studio 2008 C# code snippet download.
VS 2008 C# Code Snippet Download

Related

what is best method to document your .Net code? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
You and me both know that creating a document for codes is really boring and i opened this as a discussion that you share your experience for creating document for your code.
i think project documentation is differs from code documentation in a project documentation you can use UML to describe the whole projects,algorithms,designs, architecture.However your code documentation is very effective while your developing a DLL library or providing a web service or any other codes that will be use from other developers.
i think discussion subjects is :
1.Tools that you know useful for generating documentation
2.Methods and Rules for providing a source documentation
3.Does other developer code comment helped you what was useful
This is one of those things that the community in general tends to disagree on. Not in general... I think we all acknowledge that code documentation is A Good Thing™, but how we do it is a personal matter.
Here is my take on it:
I know it's painful, but inline documentation helps to keep you focused, as well as giving you some information you can refer to when you look back at the code.
1) I use Sandcastle to generate help files from my libraries, which I document with XML document comments.
2a) Always provide reasonable XML documentation for your public fields, properties and methods. Don't just put /// <summary>FieldName</summary>, describe what the field is for.
2b) Use inline comments sparingly. Don't comment every line, but do comment blocks of code that do something interesting or in an interesting way, just so you (or anyone else) can understand it clearly next time you read the code.
3) Abso-freaking-lutely. Reading my own code is usually pretty simple, but every developer works differently. When you have a piece of code somebody else wrote, comments can make the difference between understanding and not.

Picking a parser generator for building an interpreter for a custom language using C#? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
This is the first time I go into actually trying to implement a Domain Specific Language.
I know the basics of language grammars and Abstract Syntax Trees, however I didn't get my hands dirty in implementing them before.
I want to build a small language, simple variables/arrays and conditional statements. I want to interpret and execute the user entered code via an interpreter I build by C#. Something pretty similar in spirit to PHP tho way simpler.
I searched and I became confused.
Best parser generators I found which had good C# supports were Gold and Irony. I also found ANTLR but I saw too many people complaining about problems with C# suppots. Also, the three of those seem to lack good documentation.
My main fear is to begin working with one of them and then discovering its not usable for the task, either because of lack of good C# support, or good documentation or something else. I want something that I can begin working with "confidently" to get myself kickstarted in the project.
Could anyone help me to pick something that does the job well and guaranteed to work well with C# ?
I suggest you to use ANTLR. I wrote my own compiler (for MSIL) using it.
ANTLR has C# support and i did not found any problems with it.
U can also look at my source code (i can not be working sample, but it has ANTLT .g file) for sample.
I suggest you try TinyPG. It compiles to C#, and you can provide C# directly in the grammar.

Diff tool that can be integrated into a C# app [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have a small C# app and I'd like to provide the ability to preview diffs and accept changes. My inputs are only text files. I came across some tools like kdiff3 and winmerge and I was wondering if anyone's integrated them inside a C# app and if yes, how was it done? I also came across some nice projects on CodeProject from an earlier stackoverflow question but since those projects were written in 2004, I was wondering if you have any suggestions for an open source diff and merge tool that I can integrate? Thanks!
Have you checked out csdiff ?
http://code.google.com/p/csdiff/
You might want to checkout DiffPlex. It is (amongst other things) a library that can be used to generate text diffs. It also provides some higher level classes that provide a more complete "diff model" that should be easier to use for rendering diffs in, say, a textbox.
Personally, I have only used it for minor tasks, but it looks powerful enough to handle more sophisticated scenarios as well.
Winmerge, as you mentioned, can be integrated with other apps via the command line. Here's an example of visual studio using these command line parameters to replace the built in diff client. In regards to launching winmerge itself, I found this simple example of how to call an external program from C#.

Visual Studio 2012 c# 'code behind' and default 'event handler' code ? Where in Snippets is it or someplace else? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I wanted to try to bring forward some old snippets
I had forgotten, to change the default behaviour of VS2010 when creating code behind
c# for each event I defined either
From XML, or
From the control properties panel, or
From assigning and defining an event handler loading (overloading?) (control.event.handler += event handler;) entering the event handler without the handler defined would give you a stub subroutine at the end of the file.
All three coding actions can occur in three different setting but should create the same code behind.
Now I want to put my bells and whistles and stamp my actions with a debug, ifdefs, and
have the code explain to me in a diagnostics output what it is doing, which is generally different from what I want it to do. It can turn into a lot of typing. Snippets are way cool. And are highly personal. I'm certain as I get more experienced I will shed my training wheels. But I remember having done this in vs2010 by hacking underneath VS in its internal snippets or xml settings. It is not a regular snippet; or is it ?
There is also a way to save this in a local directory so as to override the default code behind generation/snippet. I can't seem to find this again. What is a workflow and is that
what I'm looking for ? I'm installing VS2010 express and pro and testing/porting code.
I would love to get action back. Where is it in VS2012 ?
Off of the main menu Tools->Code Snippet Manager or via the Quick Launch type "snippet". Also you may want to add the "Snippet Designer" add in via the Tools->Extension and updates.
In 2012 if you ever forget where a command is, use the Quick Launch to help one find it.

Stand alone C# compiler [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
We have a software which we use in-house for our day to day work.
It is like a customize CRM (sort of) and Bug Tracking software. We had a small team of 3 developers who had developed this software. Now this team is also working on other assignments.
Recently we are receiving a lot of request for adding functionality from users (who are our employees and all of them are developers working of different projects) in our firm. The original team that created this software does not have enough time to work on enhancing this software. So instead of spending a lot of time in updating as per request and the updating the executable of software for each user, we want to implement a programming/scripting solution that is if possible free and open source.
I was thinking of adding support for a language which is similar to C# to our application. This way the developers will add the features that they require on their own in their spare time if they really need a feature!
Can anyone point me to some such implementation already existing?
I don't know if I am taking the right decision or not regarding C# I would like to get opinion of experts on this also.
TIA
The framework already comes with a C# compiler you can use at execution time via CSharpCodeProvider.
You might want to look at the source code to Snippy, a small tool I wrote for C# in Depth - that compiles code on the fly, and can act as a reasonably simple introduction to CSharpCodeProvider.
I think I'd look at a scripting solution here; probably IronPython is the easiest to bundle and host, but others are available (including Javascript.NET, IronRuby, IronScheme, Boo, F#, etc)

Categories

Resources