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

Option to ignore missing properties in target class during ToModel #37

Closed
mungojam opened this issue May 18, 2022 · 2 comments
Closed
Labels
enhancement New feature or request PR welcome User contribution/PR is welcome

Comments

@mungojam
Copy link

I'm parsing some Toml (a python Pipfile), but only care about one of the sections in the Toml, so haven't specified all possible sections that might be in the file.

I end up getting errors for all sections that I haven't catered for:

(6,2) : error : Unable to set the property packages on object type PipFile.
(38,2) : error : Unable to set the property dev-packages on object type PipFile.
(61,2) : error : Unable to set the property pipenv on object type PipFile.

This wouldn't be the case for the standard json deserializer

@xoofx xoofx added the enhancement New feature or request label May 19, 2022
@xoofx xoofx added the PR welcome User contribution/PR is welcome label Jun 16, 2022
@TylerReid
Copy link
Contributor

I ran into this as well so created #41

@xoofx xoofx closed this as completed Jul 1, 2022
@bacongobbler
Copy link
Contributor

bacongobbler commented Oct 12, 2022

Thanks @TylerReid. #41 appears to capture simple properties, but when an object is received, I still see errors.

Test program to reproduce with Tomlyn 0.15.0:

using Tomlyn;

namespace TomlynTest;

public class SimpleModel
{
        public string? Name { get; set; }
}

class Program
{
        static void Main(string[] args)
        {
                var input = @"values = ['1','2','3']
[config]
required = false";

                var model = Toml.ToModel<SimpleModel>(input, options: new TomlModelOptions
                {
                        IgnoreMissingProperties = true,
                });

                Console.WriteLine(model);
        }
}

Output:

><> dotnet run
Unhandled exception. Tomlyn.TomlException: (2,2) : error : Unable to set the property config on object type TomlynTest.SimpleModel.

   at Tomlyn.Toml.ToModel[T](DocumentSyntax syntax, TomlModelOptions options)
   at Tomlyn.Toml.ToModel[T](String text, String sourcePath, TomlModelOptions options)
   at TomlynTest.Program.Main(String[] args) in /home/bacongobbler/code/tomlyn-test/Program.cs:line 18

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

4 participants