-
-
Save Ravenheart/0f4f47bbe14737cb01998cf86bf0396d to your computer and use it in GitHub Desktop.
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
using MongoDB.Bson.Serialization; | |
using MongoDB.Bson.Serialization.Attributes; | |
using System; | |
namespace TestConsole | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string json = "{\"Child\":{\"Height\":0.5,\"Weight\":2.9}}"; | |
try | |
{ | |
var model = BsonSerializer.Deserialize<SampleClass>(json); | |
Console.WriteLine("Success"); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.ToString()); | |
} | |
Console.ReadKey(); | |
} | |
} | |
[BsonIgnoreExtraElements] | |
public class SampleClass | |
{ | |
public SubClass Child { get; set; } | |
public SampleClass() | |
{ | |
this.Child = new SubClass(); | |
} | |
} | |
[BsonIgnoreExtraElements] | |
public class SubClass | |
{ | |
public float Height { get; set; } | |
public float Weight { get; set; } | |
} | |
} |
Author
Ravenheart
commented
Jul 21, 2016
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment