CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets My Favorites Favorites Web Code Search Snippets Search
Sign inor Register
Language: XML

propsetting Visual Studio Snippet for Settings-backed properties

509 Views   
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
      <Title>Property with Settings backend</Title>
      <Author>jerry@online.jerrynixon.com</Author>
      <Description>
      </Description>
      <HelpUrl>
      </HelpUrl>
      <Shortcut>propsetting</Shortcut>
    </Header>
  <Snippet>
    
    <Declarations>
      <Literal>
        <ID>name</ID>
        <Default>MyProperty</Default>
      </Literal>
      <Literal>
        <ID>type</ID>
        <Default>string</Default>
      </Literal>
    </Declarations>
    
    <Code Language="CSharp">
      <![CDATA[string m_$name$Name = "$name$";
        $type$ m_$name$Default = default($type$);
        public $type$ $name$
        {
            get
            {
                try { return ($type$)Windows.Storage.ApplicationData.Current.LocalSettings.Values[m_$name$Name]; }
                catch { return m_$name$Default; }
            }
            set
            {
                Windows.Storage.ApplicationData.Current.LocalSettings.Values[m_$name$Name] = value;
                Windows.Storage.ApplicationData.Current.SignalDataChanged();
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(m_$name$Name));
            }
        }
 
]]>
    </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>
by Jerry Nixon
  October 05, 2012 @ 1:01pm
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies