Can we have readonly serializers?

29 views
Skip to first unread message

Justin Dearing

unread,
Sep 23, 2012, 3:45:47 PM9/23/12
to mongodb...@googlegroups.com
First of all my motivation  is I want to be able to serialize System.Diagnostics.EventLogEntry without having to do any magic or creating a PODO class with all the properties.

Anyway, some classes like EventLogEntry have readonly properties, and you want to insert these classes into the database, even if you never read data back into the same classes. I was thinking the following:
  • Create ReadonlyPublicMemberFinderConvention that will serialize to readonly properties
  • Create an internal collection of readonly serializers.
  • Create a static method called  BsonSerializer.LookupReadonlySerializer()  that populates this collection
  • Then have the serialization calls look in this collection first (which will only ever be explicitly populated) then the read/write collection. The deserialization calls simply won't look here.
Justin

craiggwilson

unread,
Sep 23, 2012, 4:35:03 PM9/23/12
to mongodb...@googlegroups.com
This is already possible, you just need a way to let the BsonClassMap know about the readonly members.  Effectively, readonly members get serialized to the database but not deserialized from the database.  
Reply all
Reply to author
Forward
0 new messages