Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2005

Tip: Looking for answers? Try searching our database.

VS.NET 2005 snippet help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lloyd Dupont - 07 Aug 2005 08:01 GMT
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?

Signature

There are 10 kinds of people in this world. Those who understand binary and
those who don't.

Richard Blewett [DevelopMentor] - 07 Aug 2005 12:07 GMT
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] - 07 Aug 2005 12:10 GMT
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 - 07 Aug 2005 13:23 GMT
Thanks Richard!!!

Signature

There are 10 kinds of people in this world. Those who understand binary and
those who don't.

> sorry - directory should be
>
[quoted text clipped - 110 lines]
>
> [microsoft.public.dotnet.framework]
Lloyd Dupont - 07 Aug 2005 13:40 GMT
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....

Signature

There are 10 kinds of people in this world. Those who understand binary and
those who don't.

> sorry - directory should be
>
[quoted text clipped - 110 lines]
>
> [microsoft.public.dotnet.framework]

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.