DCSIMG
Code snippet for session wrapped properties - Ran Wahle's blog

Ran Wahle's blog

Code snippet for session wrapped properties

Code snippet for session wrapped properties

Long ago, I’ve written about session manager class which provides type safety while
accession Session variables.

One of it’s foundations is the very properties we write that wraps the session variables.
These properties tends to be very much alike and therefore I’ve written a code snippet
for them.

It’s shortcut is propsess , you can copy it from below

<?xml version="1.0" encoding="utf-8" ?>
 
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
 
  <CodeSnippet Format="1.0.0">
 
    <Header>
      <Title>Session based Property</Title>
      <Shortcut>propsess</Shortcut>
      <Description>
        Code snippet for property with get and set accessors
        that wraps a  session variable
      </Description>
      <Author>Ran Wahle</Author>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>type</ID>
          <ToolTip>Property type</ToolTip>
          <Default>string</Default>
        </Literal>
        <Literal>
          <ID>name</ID>
          <Default>PropName</Default>
          <ToolTip>Property name</ToolTip>
        </Literal>
        <Literal>
          <ID>sessionKey</ID>
          <Default>SessionKey</Default>
          <ToolTip>Session Key</ToolTip>
        </Literal>
        <!--<Literal>
          <ID>controlInnerProperty</ID>
          <Default>Text</Default>
          <ToolTip>Control Inner property</ToolTip>
        </Literal>-->
      </Declarations>
      <Code Language="csharp">
 
        <![CDATA[
 
        /// <summary>
        /// Put summary for $name$
        /// </summary>
        public $type$ $name$
        {
            get
            {
                return Session["$sessionKey$"] as $type$;
            }
            set
            {
               Session["$sessionKey$"] = value;
            }
        }
 
]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>
 

Enjoy Smile

kick it on DotNetKicks.com

Comments

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# August 4, 2011 12:45 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: