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

Expose "syntax to model" visitor #48

Open
cryocz opened this issue Nov 11, 2022 · 0 comments
Open

Expose "syntax to model" visitor #48

cryocz opened this issue Nov 11, 2022 · 0 comments
Labels
enhancement New feature or request PR welcome User contribution/PR is welcome

Comments

@cryocz
Copy link

cryocz commented Nov 11, 2022

Right now the syntax node to model class marshaling is hidden behind the internal class SyntaxToModelTransform. Sometimes it is useful to do "delayed" marshaling where first a TomlTable value is captured and then later marshaled into its model class.

Consider a scenario where a modular application loads its configuration from a single file. A hypothetical T Toml.ToModel<T>(TomlObject) method would be very useful here.

class ConfigProvider {
  private readonly TomlTable _toml;

  public T? LoadConfig<T>(string section) {
    if (_toml[section] is not TomlObject obj)
      return default;
    return Toml.ToModel<T>(obj);
  }
}

This system is already implemented in the SyntaxToModelTransform class, it is just not exposed to the outside world. Right now the only way to achieve this behavior is to first transform the table back into TOML and then transform that string into the model class. This is not only wasteful, but also destroys TOML trivia.

@cryocz cryocz changed the title Expose syntax to model visitor Expose "syntax to model" visitor Nov 11, 2022
@xoofx xoofx added enhancement New feature or request PR welcome User contribution/PR is welcome labels Nov 14, 2022
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