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

Is there any way to mark a model member as required? #64

Open
fgimian opened this issue May 29, 2023 · 0 comments
Open

Is there any way to mark a model member as required? #64

fgimian opened this issue May 29, 2023 · 0 comments
Labels
enhancement New feature or request PR welcome User contribution/PR is welcome

Comments

@fgimian
Copy link

fgimian commented May 29, 2023

Hey there, thanks heaps for your awesome library!

I was just wondering if it was possible to throw an exception if a particular model field is missing from TOML similar to JsonRequired:

e.g.

using Tomlyn;

var toml = """
full_name = "Mr Happy"
# age = missing!
""";

var person = Toml.ToModel<Person>(toml);

Console.WriteLine($"Person {person.FullName} with age {person.Age}");

public record Person
{
    public string? FullName { get; set; }
    public int? Age { get; set; }
}

This code doesn't throw an exception and simply sets Age to null. I understand that you can specify default values via a parameterless constructor but I was curious if you can set the field as a mandatory / required property and fail when converting using ToModel if the property is missing?

Thanks heaps!
Fotis

@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