Advertisement
zippy1981

Mongo Bson Serialization of null Interface properties.

Sep 23rd, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3.  
  4. using MongoDB.Bson;
  5. using MongoDB.Bson.Serialization;
  6. using MongoDB.Driver;
  7.  
  8. namespace ConsoleApplication2
  9. {
  10.     public interface IProp
  11.     {
  12.         string AString { get; set; }
  13.     }
  14.  
  15.     public class PropImpl:IProp
  16.     {
  17.         public string AString { get; set; }
  18.     }
  19.  
  20.     public class SuperClass
  21.     {
  22.         public string Name { get; set; }
  23.         public IProp AProp { get; set; }
  24.     }
  25.  
  26.     class Program
  27.     {
  28.         private static MongoServer server = MongoServer.Create("mongodb://localhost/?safe=true");
  29.         private static MongoDatabase db = server["InterfaceTest"];
  30.         static void Main()
  31.         {
  32.             var superClass1 = new SuperClass
  33.                 {
  34.                     Name = Guid.NewGuid().ToString(),
  35.                     AProp = new PropImpl()
  36.                 };
  37.             var superClass2 = new SuperClass
  38.             {
  39.                 Name = Guid.NewGuid().ToString()
  40.             };
  41.             BsonSerializer.LookupSerializer(typeof(PropImpl));
  42.             Debug.Print("superClass1: {0}", superClass1.ToJson());
  43.             Debug.Print("superClass2: {0}", superClass2.ToJson());
  44.             //var collection = db["PropA"].Insert(superClass);
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement