This is a somewhat unique problem I think... I can solve it easily in js/ts but am kinda stuck trying to implement this in the c# solution if at all possible.
Keeping it simple, so as not to write a novel here, I'm trying to improve some crappy json serialization. It's using dictionaries within dictionaries currently and it's assy to parse in JS. I wrote a TS library that "unpacks" the data into a more palatable format, but I'd love to move that server-side. The model is an xml object with elements unkown to the application (because it's defined in a CMS and can be modified any time even while the app is running) and because Vendor, I'm stuck with c#.
Super easy in JS - c#'s strong typing is killing me here.
How would you create this addKvp function in c# (where element would be of type object, i assume)
function addKvp (element, key, value) { element[key] = value; }
var abc = {};
addKvp(abc, "foo", "bar");
console.log(abc.foo);
where "key" is not a member of element.... yet.
The other directions I could tackle this from is maybe by manipulating the json serialization somehow or putting my typescript library that does exactly this in a node express server and have it sit between the two - but this'd be the "simplest" solve, if it is possible. It feels very against the c# grain.
JObjectforabcand addvalueusingJToken.FromObject(), i.e.element[key] = JToken.FromObject(value);. Or you could useExpandoObjectforabc, i.e.dynamic abc = new ExpandoObject().