Home > Archive > Visual Studio > August 2005 > VS.NET 2005 snippet help
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
VS.NET 2005 snippet help
|
|
| Lloyd Dupont 2005-08-07, 4:01 am |
| I would like to write a template / snippet for property, as they more or
less all follow the same verbose template.
Or maybe I just would like to edit the existing one?
Anyway I would like to have this (psedo-code) template
<object> <varname>;
public <object> <Propname>
{
get { return <varname>; }
set
{
if(<varname> == value)
return;
<varname> = value;
if(<Propname>Changed != null)
<Propname>Changed(this, EventArgs.Empty);
}
}
public event <EventHandler> <Propname>Changed;
how do I do that? what file shoulf I change?
--
There are 10 kinds of people in this world. Those who understand binary and
those who don't.
| |
| Richard Blewett [DevelopMentor] 2005-08-07, 9:01 am |
| This should do what you want
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>prope</Title>
<Shortcut>prope</Shortcut>
<Description>Code snippet for property and backing field with event</Description>
<Author>Dotnet Consulting Ltd</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>Property type</ToolTip>
<Default>int</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip>Property name</ToolTip>
<Default>MyProperty</Default>
</Literal>
<Literal>
<ID>field</ID>
<ToolTip>The variable backing this property</ToolTip>
<Default>myVar</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[private $type$ $field$;
public $type$ $property$
{
get { return $field$;}
set
{
if( $field$ == value )
return;
$field$ = value;
if( $property$Changed != null )
$property$Changed(this, EventArgs.Empty);
}
}
public event EventHandler $property$Changed;
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
put it in a file (say prope.snippet) and put it in the
C:\Program Files\Microsoft Visual Studio 8\VC#\Snippets
directory
Regards
Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
I would like to write a template / snippet for property, as they more or
less all follow the same verbose template.
Or maybe I just would like to edit the existing one?
Anyway I would like to have this (psedo-code) template
<object> <varname>;
public <object> <Propname>
{
get { return <varname>; }
set
{
if(<varname> == value)
return;
<varname> = value;
if(<Propname>Changed != null)
<Propname>Changed(this, EventArgs.Empty);
}
}
public event <EventHandler> <Propname>Changed;
how do I do that? what file shoulf I change?
--
There are 10 kinds of people in this world. Those who understand binary and
those who don't.
[microsoft.public.dotnet.framework]
| |
| Richard Blewett [DevelopMentor] 2005-08-07, 9:01 am |
| sorry - directory should be
C:\Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\Visual C#
Regards
Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
This should do what you want
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>prope</Title>
<Shortcut>prope</Shortcut>
<Description>Code snippet for property and backing field with event</Description>
<Author>Dotnet Consulting Ltd</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>Property type</ToolTip>
<Default>int</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip>Property name</ToolTip>
<Default>MyProperty</Default>
</Literal>
<Literal>
<ID>field</ID>
<ToolTip>The variable backing this property</ToolTip>
<Default>myVar</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[private $type$ $field$;
public $type$ $property$
{
get { return $field$;}
set
{
if( $field$ == value )
return;
$field$ = value;
if( $property$Changed != null )
$property$Changed(this, EventArgs.Empty);
}
}
public event EventHandler $property$Changed;
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
put it in a file (say prope.snippet) and put it in the
C:\Program Files\Microsoft Visual Studio 8\VC#\Snippets
directory
Regards
Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
I would like to write a template / snippet for property, as they more or
less all follow the same verbose template.
Or maybe I just would like to edit the existing one?
Anyway I would like to have this (psedo-code) template
<object> <varname>;
public <object> <Propname>
{
get { return <varname>; }
set
{
if(<varname> == value)
return;
<varname> = value;
if(<Propname>Changed != null)
<Propname>Changed(this, EventArgs.Empty);
}
}
public event <EventHandler> <Propname>Changed;
how do I do that? what file shoulf I change?
--
There are 10 kinds of people in this world. Those who understand binary and
those who don't.
[microsoft.public.dotnet.framework]
[microsoft.public.dotnet.framework]
| |
| Lloyd Dupont 2005-08-07, 9:01 am |
| Thanks Richard!!!
--
There are 10 kinds of people in this world. Those who understand binary and
those who don't.
"Richard Blewett [DevelopMentor]" <richardb@NOSPAMdevelop.com> wrote in
message news:eXkQgC0mFHA.3960@TK2MSFTNGP12.phx.gbl...
> sorry - directory should be
>
> C:\Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\Visual C#
>
> Regards
>
> Richard Blewett - DevelopMentor
> http://www.dotnetconsult.co.uk/weblog
> http://www.dotnetconsult.co.uk
>
> This should do what you want
>
> <?xml version="1.0" encoding="utf-8" ?>
> <CodeSnippets
> xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
> <CodeSnippet Format="1.0.0">
> <Header>
> <Title>prope</Title>
> <Shortcut>prope</Shortcut>
> <Description>Code snippet for property and backing field with
> event</Description>
> <Author>Dotnet Consulting Ltd</Author>
> <SnippetTypes>
> <SnippetType>Expansion</SnippetType>
> </SnippetTypes>
> </Header>
> <Snippet>
> <Declarations>
> <Literal>
> <ID>type</ID>
> <ToolTip>Property type</ToolTip>
> <Default>int</Default>
> </Literal>
> <Literal>
> <ID>property</ID>
> <ToolTip>Property name</ToolTip>
> <Default>MyProperty</Default>
> </Literal>
> <Literal>
> <ID>field</ID>
> <ToolTip>The variable backing this property</ToolTip>
> <Default>myVar</Default>
> </Literal>
> </Declarations>
> <Code Language="csharp">
> <![CDATA[private $type$ $field$;
>
> public $type$ $property$
> {
> get { return $field$;}
> set
> {
> if( $field$ == value )
> return;
>
> $field$ = value;
>
> if( $property$Changed != null )
> $property$Changed(this, EventArgs.Empty);
> }
> }
>
> public event EventHandler $property$Changed;
> $end$]]>
> </Code>
> </Snippet>
> </CodeSnippet>
> </CodeSnippets>
>
> put it in a file (say prope.snippet) and put it in the
>
> C:\Program Files\Microsoft Visual Studio 8\VC#\Snippets
>
> directory
>
> Regards
>
> Richard Blewett - DevelopMentor
> http://www.dotnetconsult.co.uk/weblog
> http://www.dotnetconsult.co.uk
>
> I would like to write a template / snippet for property, as they more or
> less all follow the same verbose template.
> Or maybe I just would like to edit the existing one?
>
> Anyway I would like to have this (psedo-code) template
>
>
> <object> <varname>;
> public <object> <Propname>
> {
> get { return <varname>; }
> set
> {
> if(<varname> == value)
> return;
>
> <varname> = value;
> if(<Propname>Changed != null)
> <Propname>Changed(this, EventArgs.Empty);
> }
> }
>
> public event <EventHandler> <Propname>Changed;
>
> how do I do that? what file shoulf I change?
>
>
> --
> There are 10 kinds of people in this world. Those who understand binary
> and
> those who don't.
>
>
>
> [microsoft.public.dotnet.framework]
>
> [microsoft.public.dotnet.framework]
| |
| Lloyd Dupont 2005-08-07, 9:01 am |
| Thanks, with your guidance I just created the Super Property Snippet!!!
But I had to use the snippet manager to add it.
Saving it in the location (where there are plenty of other snippet to read
to learn the syntax) didn't work.. I even tryed to restart VS, to no
result....
--
There are 10 kinds of people in this world. Those who understand binary and
those who don't.
"Richard Blewett [DevelopMentor]" <richardb@NOSPAMdevelop.com> wrote in
message news:eXkQgC0mFHA.3960@TK2MSFTNGP12.phx.gbl...
> sorry - directory should be
>
> C:\Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\Visual C#
>
> Regards
>
> Richard Blewett - DevelopMentor
> http://www.dotnetconsult.co.uk/weblog
> http://www.dotnetconsult.co.uk
>
> This should do what you want
>
> <?xml version="1.0" encoding="utf-8" ?>
> <CodeSnippets
> xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
> <CodeSnippet Format="1.0.0">
> <Header>
> <Title>prope</Title>
> <Shortcut>prope</Shortcut>
> <Description>Code snippet for property and backing field with
> event</Description>
> <Author>Dotnet Consulting Ltd</Author>
> <SnippetTypes>
> <SnippetType>Expansion</SnippetType>
> </SnippetTypes>
> </Header>
> <Snippet>
> <Declarations>
> <Literal>
> <ID>type</ID>
> <ToolTip>Property type</ToolTip>
> <Default>int</Default>
> </Literal>
> <Literal>
> <ID>property</ID>
> <ToolTip>Property name</ToolTip>
> <Default>MyProperty</Default>
> </Literal>
> <Literal>
> <ID>field</ID>
> <ToolTip>The variable backing this property</ToolTip>
> <Default>myVar</Default>
> </Literal>
> </Declarations>
> <Code Language="csharp">
> <![CDATA[private $type$ $field$;
>
> public $type$ $property$
> {
> get { return $field$;}
> set
> {
> if( $field$ == value )
> return;
>
> $field$ = value;
>
> if( $property$Changed != null )
> $property$Changed(this, EventArgs.Empty);
> }
> }
>
> public event EventHandler $property$Changed;
> $end$]]>
> </Code>
> </Snippet>
> </CodeSnippet>
> </CodeSnippets>
>
> put it in a file (say prope.snippet) and put it in the
>
> C:\Program Files\Microsoft Visual Studio 8\VC#\Snippets
>
> directory
>
> Regards
>
> Richard Blewett - DevelopMentor
> http://www.dotnetconsult.co.uk/weblog
> http://www.dotnetconsult.co.uk
>
> I would like to write a template / snippet for property, as they more or
> less all follow the same verbose template.
> Or maybe I just would like to edit the existing one?
>
> Anyway I would like to have this (psedo-code) template
>
>
> <object> <varname>;
> public <object> <Propname>
> {
> get { return <varname>; }
> set
> {
> if(<varname> == value)
> return;
>
> <varname> = value;
> if(<Propname>Changed != null)
> <Propname>Changed(this, EventArgs.Empty);
> }
> }
>
> public event <EventHandler> <Propname>Changed;
>
> how do I do that? what file shoulf I change?
>
>
> --
> There are 10 kinds of people in this world. Those who understand binary
> and
> those who don't.
>
>
>
> [microsoft.public.dotnet.framework]
>
> [microsoft.public.dotnet.framework]
|
|
|
|
|