C# MongoDB snippet

Here’s a handy snippet I use for building out data models for MongoDB.  Feel free to use, modify, share, and plagiarize as needed.

<?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>BSON Serialization Property</Title>
      <Author>Steve Konves</Author>
      <Description>
      </Description>
      <HelpUrl>
      </HelpUrl>
      <Shortcut>bprop</Shortcut>
    </Header>
    <Snippet>
      <Declarations>
        <Literal Editable="true">
          <ID>Property Name</ID>
          <ToolTip>
          </ToolTip>
          <Default>BsonProperty</Default>
          <Function>
          </Function>
        </Literal>
        <Literal Editable="true">
          <ID>Type</ID>
          <ToolTip>
          </ToolTip>
          <Default>string</Default>
          <Function>
          </Function>
        </Literal>
        <Literal Editable="true">
          <ID>Abbr</ID>
          <ToolTip>
          </ToolTip>
          <Default>bp</Default>
          <Function>
          </Function>
        </Literal>
        <Literal Editable="true">
          <ID>BsonProperty</ID>
          <ToolTip>BsonProperty</ToolTip>
          <Default>BsonProperty</Default>
          <Function>
          </Function>
        </Literal>
      </Declarations>
      <Code Language="csharp"><![CDATA[[BsonRequired]
        [BsonElement(_$BsonProperty$ElementName)]
        public $Type$ $BsonProperty$ { get; set; }
        private const string _$BsonProperty$ElementName = "$Abbr$";
        public static readonly string $BsonProperty$ElementName = _$BsonProperty$ElementName;]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

 

Posted on September 27, 2012 at 6:25 pm by Steve Konves · Permalink
In: C#, Development

Leave a Reply