Monthly Archives: November 2012

Code Snippets – Disable Warning 4014

I use code snippets extensively. I don’t think it makes sense to do without them if you do any XAML work, though what you use them for is actually the code behind where lots of boilerplate code is necessary. My snippets collection consists mostly of modified Dr WPF’s dependency property snippets and various types of observable property snippets. Today I am working on cleaning up some code in WinRT XAML Toolkit and decided a snippet to disable warnings could be helpful, so here it is (also added to my collection on dropbox). Just use the sw shortcut for this Suppress Warning snippet.

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <SnippetTypes>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
      <Shortcut>sw</Shortcut>
      <Title>Suppress Warning</Title>
      <Description>Surrounds with a #pragma warning disable/restore block.</Description>
      <Author>Filip Skakun</Author>
      <HelpUrl>https://xyzzer.wordpress.com</HelpUrl>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>warninglist</ID>
          <ToolTip>Comma separated warning list.</ToolTip>
          <Default>4014</Default>
        </Literal>
      </Declarations>
      <Code Language="csharp">
        <![CDATA[#pragma warning disable $warninglist$
$selected$$end$
#pragma warning restore $warninglist$]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>