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.