-
-
Notifications
You must be signed in to change notification settings - Fork 485
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
Renaming a property via an attribute + better aliasing method #495
Comments
You can use the |
My problem is I need the EnsureRoundtrip() on the serializer while renaming the prop and also keep its value. The current aliasing won't work. Side question: Does naming conventions require both the name in the serialized file and the name in the code to be the same or does it only refer to the former? In any case, is there an easy way of reading a property with name X and serializing it with name Y (which corresponds to a rename)? |
Can you provide more details ? I'm not sure what you are trying to achieve. Can you explain in detail what you tried to do, what output you got and what you would expect ? This is an example that does what I tried to explain: https://dotnetfiddle.net/awXNnp Regarding naming conventions, the purpose of naming conventions is exactly to have different ways of naming identifiers in YAML and C#. The naming conventions assume that C# identifiers follow the standard conventions, and provide a way to map to the corresponding YAML identifier. |
I see. Thanks. |
You can do that if you use a different configuration for the serializer and the deserializer. Instead of adding the var deserializer = new DeserializerBuilder()
.WithAttributeOverride<Data>(d => d.Text, new YamlMemberAttribute
{
Alias = "my_text",
ApplyNamingConventions = false
})
.Build();
var serializer = new SerializerBuilder()
.WithAttributeOverride<Data>(d => d.Text, new YamlMemberAttribute
{
Alias = "MY_TEXT",
ApplyNamingConventions = false
})
.EnsureRoundtrip()
.Build(); |
That makes sense! Thank you, Antoine! |
Looks like this was answered closing it. |
Hey,
Great library, thanks!
Something that it lacks is the ability to easily rename a node. Unity does this via a FormerlySerializedAs attribute. I'm sure it's not a big deal integrating a similar functionality here.
In my particular case, I want to rename some properties from "prop" to "Prop" to follow C# Naming convention, but that's very hard to do manually on a big project.
Can this functionality be added ?
Also, another very useful feature would be having something like this:
In case the property is found both as name and Name inside the serialized data, use the first one that has a compatible scalar type.
The text was updated successfully, but these errors were encountered: