Example #1
0
 public static void Test_EnumAsString_01(bool setEnumConvention = false)
 {
     if (setEnumConvention)
     {
         ConventionPack conventions = new ConventionPack();
         conventions.Add(new EnumRepresentationConvention(BsonType.String));
         ConventionRegistry.Register("EnumRepresentationConvention", conventions, t => true);
     }
     try
     {
         Test_Class_Enum_01 enum_01 = new Test_Class_Enum_01 {
             enum_01 = Test_Enum_01.Value3
         };
         Trace.WriteLine("enum_01 enum_01 {0}", enum_01.enum_01);
         BsonDocument document = enum_01.ToBsonDocument();
         Trace.WriteLine("enum_01.ToBsonDocument {0}", document.ToJson());
         Test_Class_Enum_01 enum_02 = BsonSerializer.Deserialize <Test_Class_Enum_01>(document);
         Trace.WriteLine("enum_02 enum_01 {0}", enum_02.enum_01);
     }
     finally
     {
         if (setEnumConvention)
         {
             ConventionRegistry.Remove("EnumRepresentationConvention");
         }
     }
 }
Example #2
0
        public static void Test_EnumDerialization_01(string json)
        {
            Trace.WriteLine("json \"{0}\"", json);
            Test_Class_Enum_01 enum_01 = BsonSerializer.Deserialize <Test_Class_Enum_01>(json);

            Trace.WriteLine("enum_01 enum_01 {0}", enum_01.enum_01);
        }
Example #3
0
 public static void Test_EnumAsString_01(bool setEnumConvention = false)
 {
     if (setEnumConvention)
     {
         ConventionPack conventions = new ConventionPack();
         conventions.Add(new EnumRepresentationConvention(BsonType.String));
         ConventionRegistry.Register("EnumRepresentationConvention", conventions, t => true);
     }
     try
     {
         Test_Class_Enum_01 enum_01 = new Test_Class_Enum_01 { enum_01 = Test_Enum_01.Value3 };
         Trace.WriteLine("enum_01 enum_01 {0}", enum_01.enum_01);
         BsonDocument document = enum_01.ToBsonDocument();
         Trace.WriteLine("enum_01.ToBsonDocument {0}", document.ToJson());
         Test_Class_Enum_01 enum_02 = BsonSerializer.Deserialize<Test_Class_Enum_01>(document);
         Trace.WriteLine("enum_02 enum_01 {0}", enum_02.enum_01);
     }
     finally
     {
         if (setEnumConvention)
             ConventionRegistry.Remove("EnumRepresentationConvention");
     }
 }