[CSHARP-1076] Comment on: "mongodb-ecosystem/tutorial/serialize-documents-with-the-csharp-driver.txt" Created: 10/Jun/14 Updated: 04/Apr/15 Resolved: 04/Apr/15 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Blocker - P1 |
| Reporter: | Docs Collector User (Inactive) | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | collector-298ba4e7 | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
VS2013, C#, Win8.1, etc... Location: http://docs.mongodb.org/ecosystem/tutorial/serialize-documents-with-the-csharp-driver/ |
||
| Description |
|
Hi Steps: 4. Changed Person class to Name and OldAge properties Code: public string Name { get; set; } public int OldAge { get; set; }[BsonExtraElements] public IDictionary<string, object> ExtraElements { get; set; } public void BeginInit() { // } public void EndInit() if (!ExtraElements.TryGetValue("Alive", out ageValue)) { return; }var age = (int)ageValue; ExtraElements.Remove("Age"); OldAge = age; Problem: When deserializing the second record, ExtraElements is null. My resolution: The only way that I could make that code work was to do either of the following: 1. Add a constructor to new up ExtraElements public Person() 2. Check if ExtraElements is null if ((ExtraElements == null) || (!ExtraElements.TryGetValue("Age", out ageValue))) Reporter: Richard O'Neil |