Can I trigger an exception on missing fields? #813
-
Hey, so I currently have a yaml with 3 fields, doesn't matter what their names or values. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Also, can I generate a comment for every field, during serialization? For example, adding a comment in the field with YamlMember or something? |
Beta Was this translation helpful? Give feedback.
-
You wouldn’t get an exception when your yaml has 3 fields and your class has 4. You would only get an exception a field in your yaml doesn’t exist on your class. You should be able to use the yamlmember attribute on fields and properties to add comments in your yaml without issue. |
Beta Was this translation helpful? Give feedback.
-
There’s pretty good comments on the yamlmemberattribute that you can review. They should also show up in intelligence in visual studio. https://github.com/aaubry/YamlDotNet/blob/master/YamlDotNet/Serialization/YamlMemberAttribute.cs I don’t think there’s any formal documentation on it. |
Beta Was this translation helpful? Give feedback.
-
You would also need to check if the fields get set by yourself. One potential reliable solution would be to use properties with a setter that keep track when the property was set. |
Beta Was this translation helpful? Give feedback.
There’s pretty good comments on the yamlmemberattribute that you can review. They should also show up in intelligence in visual studio.
https://github.com/aaubry/YamlDotNet/blob/master/YamlDotNet/Serialization/YamlMemberAttribute.cs
I don’t think there’s any formal documentation on it.