Can I Read/Write Anchor Names Somehow?
I want to be able to control the names of anchors being emitted, more specifically:
- How do I control the output name of an anchor?
- How can I get the anchor name after dezerialisation?
public class MyNode
{
public string Name { get; set; }
public string MyScalar { get; set; }
}
public class MyNodeList
{
public IList<MyNode> Items { get; set; }
}
var node = new MyNode
{
[YamlAnchor] // this attribute doesn´t exist, but is there something similar?
Name = "i_want_this_to_be_the_anchor_name",
MyScalar = "hello"
};
var list = new MyNodeList() {
node,
node,
node,
node
}
How can I get this:
MyNode:
- &i_want_this_to_be_the_anchor_name
Name: some_name
MyScalar: hello
Items:
- *i_want_this_to_be_the_anchor_name
- *i_want_this_to_be_the_anchor_name
- *i_want_this_to_be_the_anchor_name
- *i_want_this_to_be_the_anchor_name
instead of this:
MyNode:
- &o2
Name: some_name
MyScalar: hello
Items:
- *o2
- *o2
- *o2
- *o2
I barely invested in alias handling as it was a niche feature (I'm not saying it's not useful) so this might require a few changes in the code to support this scenario (feel free to PR). Note also that as I explained in #28, aliasing is partially implemented, supporting only forward but not backward aliasing, that might not work well in write-re-read scenarios...
Ok, then I know! Any pointers to where in the code I might start are appreciated. I might do a pull request later depending on where we land with this.
Thanks for your effort with this library, very useful!
This is mostly handled in AnchorSerializer.cs. For the problem described in #28 (backward reference), that might require more work than just adapting the AnchorSerializer