Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't serialize get-only properties #59

Open
jmyersmsft opened this issue Mar 27, 2023 · 0 comments
Open

Can't serialize get-only properties #59

jmyersmsft opened this issue Mar 27, 2023 · 0 comments
Labels
enhancement New feature or request PR welcome User contribution/PR is welcome

Comments

@jmyersmsft
Copy link

jmyersmsft commented Mar 27, 2023

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"
        }
    }));
@xoofx xoofx added enhancement New feature or request PR welcome User contribution/PR is welcome labels Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PR welcome User contribution/PR is welcome
Projects
None yet
Development

No branches or pull requests

2 participants