title: Serialize a Dictionary in the "Document" representation, when the key is an Enum
body: <p>I am attempting to write "MyClass" below to a Mongo collection:</p>
  
  <pre><code>public enum MyEnum { A, B, C };
  
  public class MyClass
  {
      [BsonId(IdGenerator = typeof(StringObjectIdGenerator))]
      public string Id { get; set; }
  
      [BsonDictionaryOptions(DictionaryRepresentation.Document)]
      public Dictionary&lt;MyEnum , MyOtherClass&gt; Items { get; set; }
  }
  
  public class MyOtherClass
  {
      public string MyProp { get; set; }
  }
  </code></pre>
  
  <p>I'd like to serialize this as a document, because that is the most concise representation:</p>
  
  <pre><code>{
      _id: "12345",
      Items: {
          A: {
              MyProp: "foo"   
          },
          B: {
              MyProp: "bar"   
          },
          C: {
              MyProp: "baz"   
          },
      }
  }
  </code></pre>
  
  <p>The Mongo engine throws an exception on serialization:</p>
  
  <blockquote>
    <p>When using DictionaryRepresentation.Document key values must serialize as strings.</p>
  </blockquote>
  
  <p>So, I thought that maybe I could register a convention to make enums serialize as strings:</p>
  
  <pre><code>var conventions = new ConventionPack();
  conventions.Add(new EnumRepresentationConvention(BsonType.String));
  ConventionRegistry.Register("Custom Conventions", conventions, type =&gt; type == typeof(MyClass));
  </code></pre>
  
  <p>Unfortunately, this seems to have no effect, and the engine throws the same exception.</p>
  
  <p>Is there any way to serialize a Dictionary in the Document representation, when the key is an enum type?</p>