C# Snippet – cast

One of my major sources of errors in my home game project are integer math issues. Where adding two bytes gets automatically promoted to an int.

Here is my snippet I wrote to quickly cast the issues away. I sort the error to get the cast error messages, double click to get the code highlighted, right click -> Surround With… -> cast. The default type is byte.

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>cast</Title>
      <Shortcut>cast</Shortcut>
      <Description>surrounds selection with cast</Description>
      <Author>Simeon Pilgrim</Author>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>casttype</ID>
          <Default>byte</Default>
        </Literal>
      </Declarations>
      <Code Language="csharp">
        <![CDATA[($casttype$)($selected$ )]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>