-
-
Notifications
You must be signed in to change notification settings - Fork 492
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
YamlIgnoreAttribute can not apply to overrides #271
Comments
I agree that this needs fixing. Is is necessary to add a property to control this behavior? Is there any use case where one would not want the |
I think it is very rarely that one would not want the This pattern can be used by |
The source of this bug is the fact that IMemberInfo.GetCustomAttributes actually ignores it's "inherit" parameter. https://docs.microsoft.com/en-us/dotnet/api/system.reflection.memberinfo.getcustomattributes This addresses aaubry#271
I just verified this issue is resolved with the following code and result: using YamlDotNet.Serialization;
var serializer = new SerializerBuilder()
.Build();
var test = new Y
{
NotIgnored = "hi",
Ignored = "bye"
};
Console.WriteLine(serializer.Serialize(test));
public class X
{
public string NotIgnored { get; set; }
[YamlIgnore]
public virtual string Ignored { get; set; }
}
public class Y : X
{
public override string Ignored { get => base.Ignored; set => base.Ignored = value; }
} Result: NotIgnored: hi |
While serializing
CfgFile
to yaml, the overridenPath
was write to the output which is not desired.Yes I can give a
[YamlIgnore]
to overridden property, but what if I have 100 or more derived class and 10 or more properties per class have to attach a[YamlIgnore]
?It's better to append a property
ApplyToOverrides
to indicate this attribute should apply to overrides, likeScriptIgnore
inSystem.Web.Script.Serialization
:ApplyToOverrides
ofScriptIgnore
inSystem.Web.Script.Serialization
The text was updated successfully, but these errors were encountered: