Repository navigation
BSON Serializer
atheken edited this page Aug 13, 2010
·
28 revisions
MongoSharp’s BSON serializer is very powerful, but you must be careful not to abuse it.
- All readable properties may be:
- int
- bool
- double (floats will be stored as doubles in the db)
- datetime
- string
- byte[]
- BSONOID (this is the default "_id" value that’s generated if you don’t specify something different)
- Regex
- Guid
- IEnumerable
- T ("where T:class, new()" and follows this rule. )
- A few other types should be supported soon.
- Cyclic graphs are not checked and attempting to serialize them will crash your app, maybe someday this will change, but not this day.
- All public instance properties of the type must be writeable
- All of the types above are supported with three important caveats:
- value-types must use their correspondant Nullable type (i.e. the class must define "int?" properties, rather than "int" properties)
- IEnumerable is always deserialized as List, therefore, your IEnumerable properties must be assignable from List
- Remember how floats are stored as doubles well they are deserialized to "double?"