Snippet for ViewState-Backed Properties

Inspired by Fritz’ post, I created this little snippet on the train…

<?xml version=1.0 encoding=utf-8 ?>

<CodeSnippets  xmlns=http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet>

  <CodeSnippet Format=1.0.0>

    <Header>

      <Title>aspprop</Title>

      <Shortcut>aspprop</Shortcut>

      <Description>New ASP.NET Property with ViewState</Description>

      <Author>Dominick Baier</Author>

      <SnippetTypes>

        <SnippetType>Expansion</SnippetType>

      </SnippetTypes>

    </Header>

    <Snippet>

      <Declarations>

        <Literal>

          <ID>name</ID>

          <ToolTip>Property Name</ToolTip>

          <Default>MyProperty</Default>

        </Literal>

        <Object>

          <ID>type</ID>

          <ToolTip>Property Type</ToolTip>

          <Default>string</Default>

        </Object>

        <Literal>

          <ID>DefaultValue</ID>

          <ToolTip>Default Value</ToolTip>

          <Default>“”</Default>

        </Literal>

      </Declarations>

 

      <Code Language=csharp>

        <![CDATA[

  public $type$ $name$

  {

      get { return ($type$)ViewState[“$name$”] ?? $DefaultValue$; }

      set { ViewState[“$name$”] = value; }

  }

  $end$]]>

      </Code>

    </Snippet>

  </CodeSnippet>

</CodeSnippets>

Name this file “aspprop.snippet” and copy it to My Documents/Visual Studio 2005/Code Snippets/Visual C#/My Code Snippets.

 

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s