Coder Social home page Coder Social logo

Comments (4)

Nidhi1819 avatar Nidhi1819 commented on June 12, 2024

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.

from yamldotnet.

EdwardCooke avatar EdwardCooke commented on June 12, 2024

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.

public sealed class AnchorAssigner : PreProcessingPhaseObjectGraphVisitorSkeleton, IAliasProvider

from yamldotnet.

EdwardCooke avatar EdwardCooke commented on June 12, 2024

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.

from yamldotnet.

BBoldenow-Alt avatar BBoldenow-Alt commented on June 12, 2024

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 VisitObject events, but the GetAlias method is never called. Is there something I'm missing to use this Alias Provider?

Edit:

I was able to get this working by adding the following line to the SerializerBuilder

.WithEmissionPhaseObjectGraphVisitor(args => new AnchorAssigningObjectGraphVisitor(args.InnerVisitor, args.EventEmitter, anchorNaming),
w => w.InsteadOf<AnchorAssigningObjectGraphVisitor>())

from yamldotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.