I have a dynamic object being used as a parameter on a ApiController. e.e:
public class Shape
{
public dynamic Coordinates { get; set; }
public string Id { get; set; }
public string Type { get; set; }
}
The coordinates for any shape are different, a circle will have a centre and radius, a line has an x1, y1, x2, y2 etc.
I am trying to store this object in Mongo.
What I am hoping for is:
{
"Shapes": [
{
"Coordinates": {
"x1": 1,
"y1": 2,
"x2": 3,
"y2": 4
}
},
"Type": "line"
},
{
"Coordinates": "{ "x" : 10, "y" : 20, "r" : 30,},
"Type": "circle"
}
],
}
When I use BsonExtensionMethods.ToJson(coordinates) I get
{
"Shapes": [
{
"Coordinates": "{ \"x1\" : [], \"y1\" : [], \"x2\" : [], \"y2\" : [] }",
"Type": "line"
}
],
}
When I use (JObject) coordinates I get:
{
"Shapes": [
{
"Coordinates": {
"_t": "Newtonsoft.Json.Linq.JObject, Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed",
"_v": {
"x1": [
],
"y1": [
],
"x2": [
],
"y2": [
]
}
},
"Type": "line"
}
],
}
I'd rather not haver to resort to storing it as a string. How do I convince .NET that I want to store the dynamic object's values?