Giter Club home page Giter Club logo

Comments (13)

szahn avatar szahn commented on July 3, 2024

Is there documentation on how to implement your own visitor pattern during implementation or intercept the event emitter such that you can define a style (flow or block) for a particular field in the object graph?

from yamldotnet.

szahn avatar szahn commented on July 3, 2024

I was able to set the sequence style to flow only on primitive arrays by adding this code to the VisitSequenceStart() method in AnchorAssigningObjectGraphVisitor class. However, there should be a better way to do this, perhaps making it easier to pass in your own visitor when instantiating the serializer class.

if (sequenceType.IsArray && elementType.IsPrimitive)
{
info.Style = Core.Events.SequenceStyle.Flow;
}

from yamldotnet.

aaubry avatar aaubry commented on July 3, 2024

The Serializer class is meant to be a simple facade for the various classes that collaborate to the serialization process. However, it is still work in progress and that's the reason why it is not yet possible to alter the visitors that will be used, but this feature is definitely on top of the list. Your requirement of emitting arrays as flow sequences is the kind of usage that I had in mind when I started this refactoring.

from yamldotnet.

aaubry avatar aaubry commented on July 3, 2024

Now that version 2.0.0 is out, I think we should work on making the Serializer more extensible. I will keep you comments in mind while working on it. Thanks

from yamldotnet.

loudenvier avatar loudenvier commented on July 3, 2024

Is flow style for sequences implemented in the current version? I was using YamlDotNet to dump objects but since I've got a few relatively large byte arrays it is making the dump next to unreadable (which defeats the purpose of Yaml :-) ) I was expecting something in SerializerOptions but didn't find anything, then stumbled on this issue. Any news?

from yamldotnet.

zeroregard avatar zeroregard commented on July 3, 2024

Is it there yet, or does anyone have some sort of hack/fix? Much appreciated.

from yamldotnet.

zeroregard avatar zeroregard commented on July 3, 2024

Anyone stumbling upon this, I was able to do it with this fork https://github.com/xoofx/SharpYaml

You then apply this attribute on the fields you want to have a different style:
[SharpYaml.Serialization.YamlStyle(YamlStyle.Flow)]

from yamldotnet.

samsmithnz avatar samsmithnz commented on July 3, 2024

@mathiassiig Is it possible to submit this as a pull request to the main branch? Especially with GitHub Actions YAML using this in places, it would be useful to have this functionality.

from yamldotnet.

EdwardCooke avatar EdwardCooke commented on July 3, 2024

This issue appears to be abandoned, I'm going to close it. I believe this is already implemented.

from yamldotnet.

cmeeren avatar cmeeren commented on July 3, 2024

I can't see any information in this issue or linked issues that this is implemented. Is it, and if so, how can it be accomplished?

Also, is there any way to set max line length for flow-style arrays (making them break when the max length has been reached)?

from yamldotnet.

EdwardCooke avatar EdwardCooke commented on July 3, 2024

We don’t have a way of doing that in yamldotnet that I’m aware of. We’re very grateful for pull requests if you want to create one.

from yamldotnet.

cmeeren avatar cmeeren commented on July 3, 2024

Thanks. Unfortunately swamped. I found a (hacky?) workaround: In Visit(YamlSequenceNode sequence), check the NodeType of the items of the sequence and check if they are YamlNodeType.Scalar.

In any case, it seems this issue was closed erroneously then. You may consider opening it, for clarity.

from yamldotnet.

EdwardCooke avatar EdwardCooke commented on July 3, 2024

I closed because there was no comment for 3 years.

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.