aaubry / YamlDotNet

YamlDotNet is a .NET library for YAML
MIT License
2.48k stars 466 forks source link

Process inline comments with DictionaryDeserializer. #865

Open evabalint opened 7 months ago

evabalint commented 7 months ago

Dear Antoine, Edward,

We need to process some data from comments in yaml files. In these comments we usually got some descriptions about data types, ranges, available values. So I've tried to use your solution to process the yaml files, and created a CommentNodeDeserializer to process all simple values into a ValueWithComment pair and then use it in the DictionaryDeserializer. I set this behavior only if the skipComments is set to false. I hope you can accept my solution, as we really need this feature to process our input files.

Best regards, and many thanks, Eva. PS: I closed the previous pull request, because I had it on my master branch, and the appVeyor build failed when trying to get a version number.

EdwardCooke commented 7 months ago

I'll be honest, I'm pretty hesitant with merging this in. Comments in the YAML spec (which we adhere to) are supposed to be ignored from my understanding. If they're really needed, I suspect a custom/modified node deserializer should be able to handle it without modifying any of the underlying parser/scanners. Suddenly changing/adding dictionaries or objects to dictionaries could have large unintended side effects with current consumers of the library, and that's something I really want to avoid at all costs. Let me think about this some more, and I'll get back to you.

evabalint commented 7 months ago

Hello, I do understand your reluctance. I'm going to restructure my code, so I don't have to modify the IScanner and IParser interfaces of your Core project, and make sure that it has no side-effects. Many thanks for your quick reply.