-
-
Notifications
You must be signed in to change notification settings - Fork 496
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
Set anchor tag name during serialization using YamlDotNet? #807
Comments
I am looking for answer to this thread. I am using XML file and generating YAML out of it using YamlDotNet. The YAML that gets generated has anchor tags but the name of the tags is not meaningfully. I want to control the name given to anchor tag and give a more meaningful name to it. Is there any easy way to do it or will have to write a custom emitter for it. |
I think you can replace this implementation with your own and be able to create more meaningful names. However, you may not be able to get meaningful context to generate a name that makes sense.
|
Since there was a solution provided with no feedback I’m closing this issue. If you disagree go ahead and reopen it and we can discuss more. |
@EdwardCooke - I think this is reasonable, but am having trouble getting the IAliasProvider implementation to trigger. I mostly copied the AnchorAssigner, but customized the name portion. I then provided this to my serializer like this: var anchorNaming = new CustomAnchorAssigner(new List<IYamlTypeConverter>()
{
customConverter1,
customConverter2,
customConverter3,
});
var serializerBuilder = new SerializerBuilder()
.ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitEmptyCollections)
.ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull)
.WithTypeConverter(customConverter1)
.WithTypeConverter(customConverter2)
.WithTypeConverter(customConverter3)
.WithPreProcessingPhaseObjectGraphVisitor(anchorNaming) This triggers all of the Edit: I was able to get this working by adding the following line to the .WithEmissionPhaseObjectGraphVisitor(args => new AnchorAssigningObjectGraphVisitor(args.InnerVisitor, args.EventEmitter, anchorNaming),
w => w.InsteadOf<AnchorAssigningObjectGraphVisitor>()) |
@BBoldenow-Alt @EdwardCooke EDIT: Opened a new Issue under #939 |
Please open a new issue and I’ll try and build out an example in the next bit. I have very limited access to the internet right now. |
Originally posted by @rohahn in #227 (comment)
The text was updated successfully, but these errors were encountered: