SharpYaml icon indicating copy to clipboard operation
SharpYaml copied to clipboard

Question: Can SharpYaml handle merging?

Open damageboy opened this issue 8 years ago • 3 comments
trafficstars

Yaml has support for merging which allows for sort-of templating in YAML:

---
- &CENTER { x: 1, y: 2 }
- &LEFT { x: 0, y: 2 }
- &BIG { r: 10 }
- &SMALL { r: 1 }

# All the following maps are equal:

- # Explicit keys
  x: 1
  y: 2
  r: 10
  label: center/big

- # Merge one map
  << : *CENTER
  r: 10
  label: center/big

- # Merge multiple maps
  << : [ *CENTER, *BIG ]
  label: center/big

- # Override
  << : [ *BIG, *LEFT, *SMALL ]
  x: 1
  label: center/big

Is this supported in SharpYaml?

damageboy avatar Sep 20 '17 08:09 damageboy

I don't remember exactly, but the code is in AnchorSerializer.cs

I think that I didn't implement the full stuff system that supports forward reference, so basically, it is working only when reading a YAML document, the reference was pre-declared. Why forward reference were not implemented? Don't recall exactly, but it was tricky to integrate it without too many internal changes and/or heavier serialization hooks...

xoofx avatar Sep 26 '17 21:09 xoofx

Thanks!

I'll give it a serious try then...

it is working only when reading a YAML document

Does mean it will also work when deserialiazing a document with anchors that do a back reference?

damageboy avatar Sep 27 '17 09:09 damageboy

Does mean it will also work when deserialiazing a document with anchors that do a back reference?

Sorry, was not clear. It only works with this case. Forward reference will not work.

xoofx avatar Sep 27 '17 11:09 xoofx