-
-
Notifications
You must be signed in to change notification settings - Fork 486
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
Order for inheritance #870
Comments
The way the pre-built typeinspectors are setup is that it just reads the properties/fields on the object, itself, it doesn't take into account whether the field/property is from the inherited types or not, so you'll need to build your own, here's a link to the prebuilt type converter to give you a starting point, it's pretty easy to implement. YamlDotNet/YamlDotNet/Serialization/TypeInspectors/ReadablePropertiesTypeInspector.cs Line 33 in 8472305
|
You could also use the |
You can put the yamlmember on you base classes only, and specify the order with negative numbers, like this. public abstract class LogConfigBase
{
[YamlMember(Order = -1)]
public bool Enabled { get; set; } = false;
[YamlMember(Order = -2)]
public byte Level { get; set; } = 0;
} No need to specify them on the other classes, this will put those above the others. Since this is the answer, I'm going to close this issue. |
Hello there!
The question in short is: Can I change to order, so the members of inherited classes get serialized first, without manually sorting everything?
More info:
I want to use YAML to configure my app. Every time I read the configuration file I write the just read contents back to normalize it. For my logger I have a base class defining two members, that every logger should have:
And now I'm using this to define the default behavior of all loggers and 3 specific ones:
When serializing this the inherited members are placed behind every other members. But I'd like them to be always at the top.
Instead of
Can I achieve this in a quick and simple way without creating a custom SortedTypeInspector?
The text was updated successfully, but these errors were encountered: