You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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;vartoml= """
full_name = "Mr Happy"
# age = missing!
""";varperson= Toml.ToModel<Person>(toml);
Console.WriteLine($"Person {person.FullName} with age {person.Age}");publicrecordPerson{publicstring?FullName{get;set;}publicint?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
The text was updated successfully, but these errors were encountered:
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.
This code doesn't throw an exception and simply sets
Age
tonull
. 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 usingToModel
if the property is missing?Thanks heaps!
Fotis
The text was updated successfully, but these errors were encountered: