public static void Serialize <T>(BinaryWriter writer, T document) { var type = document.GetType(); if (type.IsValueType || typeof(IEnumerable).IsAssignableFrom(type)) { throw new BsonException("Root type must be an non-enumerable object"); } { BsonSerializer s = new BsonSerializer(writer); s.WriteDocument(document); } }