Reputation: 7169
Is there a shortcut in VisualStudio to create a method, like there is "prop, tab" for a property and "ctor, tab" for a constructor?
Upvotes: 28
Views: 59241
Reputation: 223247
There is no Code snippet to create a method other than Main
, but you can do the following.
Type your to be method name, pass the parameters, once done you will notice a red underline at the beginning of method name. Click that (or click Ctrl + .), it will give you the option to create method like this:
This will generate a method like the following:
private static void MySomeMethod(int a, string b)
{
throw new NotImplementedException();
}
Upvotes: 25
Reputation: 43
Here is a guidelines to create custom code snippet.
You can make your own code snippet, or just use this template:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>create new 'not implemented' method</Title>
<Description>create new 'not implemented' method</Description>
<Shortcut>emptymethod</Shortcut>
</Header>
<Snippet>
<Code Language="CSharp">
<![CDATA[ $access specifier$ $return type$ $methodName$($params$)
{
$throw new NotImplementedException()$;
}]]>
</Code>
<Declarations>
<Literal>
<ID>access specifier</ID>
<Default>Array</Default>
</Literal>
<Literal>
<ID>return type</ID>
<Default>returnType</Default>
</Literal>
<Literal>
<ID>methodName</ID>
<Default>methodName</Default>
</Literal>
<Literal>
<ID>params</ID>
<Default>params</Default>
</Literal>
<Literal>
<ID>throw new NotImplementedException()</ID>
<Default>throw new NotImplementedException()</Default>
</Literal>
</Declarations>
</Snippet>
</CodeSnippet>
</CodeSnippets>
after you import this snippet to your visual studio,
when you press emptymethod
+ tab
, you will get new not implemented method.
Upvotes: 0
Reputation: 7
Type 'fun' then tab. Ta-da! And now I need to type more characters because the minimum allowed number of characters is 30.
Upvotes: -3
Reputation: 156
<?xml version="1.0" encoding="utf-8"?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>Generate Method Stub</Title> <Description>Create a new method</Description> <Author>Anoop Simon</Author> <Shortcut>stub</Shortcut> </Header> <Snippet> <Code Language="CSharp"> <![CDATA[public string DummyMethod(string arg1,string arg2) { return string.Empty; } ]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets>
Got to Tools --> Code Snippets Manager.. (Ctrl +K , Ctrl + B)
Import the file saved earlier
Upvotes: 10
Reputation: 189
There is another clever way for create method (extract).
This way I use if I have method and I would like part of this method move to new private method.
This will create only new private method but automatically set input parameters and output parameter.
Upvotes: 14
Reputation: 222582
check Code Snippets
sim: static int main method
svm: static void main method
Upvotes: 8