Created
January 22, 2018 15:34
-
-
Save aluanhaddad/a27b622170234b2359e2cf61e138e91d to your computer and use it in GitHub Desktop.
Bson Serialization/Deserialization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
var bson = new MongoDB.Bson.BsonDocument(new Dictionary<string, object> | |
{ | |
["ChildishField"] = "childish", | |
["AnotherChildishField"] = "more childish" | |
}); | |
var serialized = bson.ToString().Dump(); | |
MongoDB.Bson.Serialization.BsonSerializer.Deserialize<Child1>(serialized).Dump(); | |
} | |
[BsonIgnoreExtraElements] | |
[BsonKnownTypes(typeof(Child1))] | |
public abstract class MyAbstract | |
{ | |
public string DontCare; | |
} | |
[BsonIgnoreExtraElements] // comment this out and it throws as expected | |
public sealed class Child1 : MyAbstract | |
{ | |
public string ChildishField; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment