Skip to content

Instantly share code, notes, and snippets.

@rstam
Created December 17, 2010 15:29
Show Gist options
  • Save rstam/745108 to your computer and use it in GitHub Desktop.
Save rstam/745108 to your computer and use it in GitHub Desktop.
TestSerializePrivateMembers.cs
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