为 Windows 表单配置适当的序列化

问题描述 投票:0回答:1

将我的 win-forms-project 升级到 .NET 9 后,我的用户控件的属性现在出现以下错误:

WFO1000: Property 'property' does not configure the code serialization for its property content.

然后我阅读了微软对该问题的解释: https://learn.microsoft.com/en-us/dotnet/core/compatibility/windows-forms/9.0/security-analyzers

现在我了解了安全问题,但我仍然不知道如何解决它。 我不想压制此消息,我想正确处理此序列化问题。

微软在那篇文章中建议:

Review the properties flagged by the analyzer and configure appropriate serialization settings as needed.

现在我想知道:我到底该怎么做?

.net winforms serialization
1个回答
0
投票

通过声明适当的属性。例如:

如果您不想保存(即序列化)该值:

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public override Color BackColor { get => base.BackColor; set => base.BackColor = value; }

如果您想保存(即序列化)该值:

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public override Color BackColor { get => base.BackColor; set => base.BackColor = value; }
© www.soinside.com 2019 - 2024. All rights reserved.