Serializing arrays as documents in MongoDB C# driver -
i have class implements icollection<t>
interface:
class test : icollection<string> { [bsonelement("items")] private list<string> _items; [bsonelement("someotherprop")] public bool someotherproperty { get; set; } // ...icollection<string> impl }
by default (de-)serialized using arrayserializer
class, other properties or fields (even public & decorated bsonelement
attribute) ignored.
does know how can enforce class deserialized regular one?
ok, seems found solution. can @ application startup:
bsonserializer.registerserializer( typeof(test), new bsonclassmapserializer(bsonclassmap.lookupclassmap(typeof(test))));
i'm not sure, might conflict bsonclassmap.registerclassmap(...)
method phone call (i.e. methods phone call order might important) - didn't check out. note, such registration global whole app domain. if inappropriate, things little more tricky, cause can't decorate class property bsonclassmapserializer
attribute. stopped little research, cause achieved goal.
i hope find reply helpful!
c# mongodb
No comments:
Post a Comment