Advertisement
NPSF3000

Property Cache Snippet

Apr 1st, 2012
729
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 1.24 KB | None | 0 0
  1. // Ever wanted to write some quick properties that cache the base properties?
  2. // This should make your life a tad easier :P
  3. // Modify as you wish
  4. <?xml version="1.0" encoding="utf-8" ?>
  5. <CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  6.     <CodeSnippet Format="1.0.0">
  7.         <Header>
  8.             <Title>propcache</Title>
  9.             <Shortcut>propcache</Shortcut>
  10.             <Description>Code snippet for a cached property and backing field</Description>
  11.             <Author>Microsoft Corporation</Author>
  12.             <SnippetTypes>
  13.                 <SnippetType>Expansion</SnippetType>
  14.             </SnippetTypes>
  15.         </Header>
  16.         <Snippet>
  17.             <Declarations>
  18.                 <Literal>
  19.                     <ID>type</ID>
  20.                     <ToolTip>Property type</ToolTip>
  21.                     <Default>int</Default>
  22.                 </Literal>
  23.                 <Literal>
  24.                     <ID>property</ID>
  25.                     <ToolTip>Property name</ToolTip>
  26.                     <Default>MyProperty</Default>
  27.                 </Literal>
  28.                 <Literal>
  29.                     <ID>field</ID>
  30.                     <ToolTip>The variable backing this property</ToolTip>
  31.                     <Default>myVar</Default>
  32.                 </Literal>
  33.             </Declarations>
  34.             <Code Language="csharp">
  35.     <![CDATA[
  36. private $type$ _$field$;
  37. public $type$ $field$
  38. {
  39.     get { return _$field$ ?? (_$field$ = base.$field$);}
  40. }
  41.     $end$]]>
  42.             </Code>
  43.         </Snippet>
  44.     </CodeSnippet>
  45. </CodeSnippets>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement