Random programming things I'd want to remember

Tuesday, March 18, 2014

Code snippet file for a property that calls for OnPropertyChanged event

With minimal changes, this snippet will also work for PropertyChanged event. How to use:
  1. Save the following contents into a .snippet file
  2. Visual Studio -> Tools -> Code Snippets Manager (or Ctrl+K, Ctrl+B)
  3. Import, find your file
  4. While working on another ViewModel, type in propopc and enjoy

Note to self: while working on the next snippet, if variables don't show up in the result, make sure that they are included in the <Snippet> section

Helpful resource 1, helpful resource 2.

<?xml version="1.0" encoding="utf-8"?>
  <CodeSnippet Format="1.0.0">
      <Title>Property with a call to OnPropertyChanged</Title>
      <Description>Property calling OnPropertyChanged method</Description>
          <ToolTip>Replace with a private variable.</ToolTip>
          <ToolTip>Replace with a property type.</ToolTip>
          <ToolTip>Replace with a property name.</ToolTip>
      <Code Language="csharp">
  private $type$ $var$;
         public $type$ $propName$
              get { return $var$; }
                  if ($var$ == value) return;
                  $var$ = value;

No comments: