Created
December 17, 2010 15:29
-
-
Save rstam/745108 to your computer and use it in GitHub Desktop.
TestSerializePrivateMembers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using MongoDB.Bson; | |
using MongoDB.Bson.DefaultSerializer; | |
using MongoDB.Bson.Serialization; | |
using MongoDB.Driver; | |
namespace TestSerializePrivateMembers { | |
public class C { | |
static C() { | |
BsonClassMap.RegisterClassMap<C>(cm => { | |
cm.MapIdField("id"); | |
cm.MapField("x"); | |
}); | |
} | |
private int id; | |
private string x; | |
public C(int id, string x) { | |
this.id = id; | |
this.x = x; | |
} | |
public int Id { get { return id; } } | |
public string X { get { return x; } } | |
} | |
public static class Program { | |
public static void Main(string[] args) { | |
var server = MongoServer.Create("mongodb://localhost/?safe=true"); | |
var database = server["test"]; | |
var collection = database.GetCollection<C>("test"); | |
var c = new C(1234, "abc"); | |
collection.RemoveAll(); | |
collection.Insert(c); | |
var d = collection.FindOne(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment