closing } automatically

G

Guest

Does anyone know a way to make the IDE close braces in Ifs statements
(methods also) for C# ?
In VB.NET you have an automatic closing...
 
D

Dave Sexton

If your using VS.NET 2005 you can just type the word "if" and then hit tab. "if" is a built-in code snippet. You can write your
own code snippets if you'd like and place them in your "My Documents/Visual Studio 2005/Code Snippets" folder. VS.NET picks them up
without even having to restart the IDE.

If your using an older version I think you might be out of luck. Maybe you could write an addin and assign it to a specific
keyboard shortcut, but I'm not sure how difficult that would be.
 
G

Guest

Thats true, this snippet code may help in If statements...
But what about when we write a new method ? Then we have to write the 2
parenthesis and after the 2 braces...its not possible to let IDE fill it for
us, like in VB.NET right?
 
D

Dave Sexton

Hi Bruce,

You can write your own snippets, as I suggested. VS.NET 2005 even gives you intellisense for the XML schema. It really is simple.

Here's a snippet that you can name, "method.snippet" and place in your My Documents/Visual Studio 2005/Code Snippets folder. Extend
it all you want.

For now it generates the following method stub:

public $return$ $name$()
{
$end$
}

[void] is an input parameter that VS.NET 2005 treats as an input box. Tab through each input box and enter the appropriate data,
with the exception of [end]. Press the 'Enter' key when you are finished filling in the variables. [end] is where the cursor is
placed after you hit 'Enter'.

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Public Parameterless Method</Title>
<Shortcut>method</Shortcut>
<Description>Stubs out a simple, public method without any parameters.</Description>
<Author>Copyright (c) 2006 Dave Sexton</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>return</ID>
<Default>void</Default>
</Literal>
<Literal Editable="true">
<ID>name</ID>
<Default>MethodName</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[public $return$ $name$()
{
$end$
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top