Been using Tomlyn in my product and it's working well, but I was writing some tests and came across a speed bump.
It'd be nifty if we could use something like the following to generate "ad-hoc" TOML content for my tests. I use a similar pattern for JSON:
var cargoToml = Toml.FromModel(new { package = new { name = "pkgname", version = "1.0.0" } });
This doesn't work though, because the properties of anonymous types are generated as get-only, and StandardObjectDynamicAccessor.Initialize() specifically filters out get-only properties. cargoToml in that example ends up being "[package]\r\n". I think that filtering makes sense for ToModel, but it's kind of inconvenient in scenarios where I'm only generating TOML with FromModel but not parsing it.
I know I can work around with the following, but the anonymous-types version is just a bit more concise:
Toml.FromModel(
new TomlTable
{
["package"] = new TomlTable
{
["name"] = "pkgname",
["version"] = "1.0.0"
}
}));
Been using Tomlyn in my product and it's working well, but I was writing some tests and came across a speed bump.
It'd be nifty if we could use something like the following to generate "ad-hoc" TOML content for my tests. I use a similar pattern for JSON:
This doesn't work though, because the properties of anonymous types are generated as get-only, and
StandardObjectDynamicAccessor.Initialize()
specifically filters out get-only properties.cargoToml
in that example ends up being"[package]\r\n"
. I think that filtering makes sense for ToModel, but it's kind of inconvenient in scenarios where I'm only generating TOML with FromModel but not parsing it.I know I can work around with the following, but the anonymous-types version is just a bit more concise: