Expose "syntax to model" visitor
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.