阻止VS将属性值放入.Designer.cs文件中(Stop VS from putting a property value in the .Designer.cs file)

编程入门 行业动态 更新时间:2024-10-23 22:32:51
阻止VS将属性值放入.Designer.cs文件中(Stop VS from putting a property value in the .Designer.cs file)

我有一个自定义控件,我已将其放在Visual Studio 2010中的表单和c#winforms上。

当我删除窗体上的控件时,属性将自动填充到From1.Designer.cs文件中。 我想阻止特定属性出现在文件中。 我已经将它标记为[Browsable(false)]但这还不足以阻止VS干扰我的财产。 是否有一个属性让VS忽略该属性?

I have a custom control which I have dropped onto a form in Visual Studio 2010 and c# winforms.

When I drop the control on the form the properties are automatically populated in the From1.Designer.cs file. I want to stop a specific property from appearing in the file. I have already marked it as [Browsable(false)] but this is not enough to stop VS from interfering with my property. Is there an attribute to the VS to ignore the property?

最满意答案

如果要将该属性序列化,请使用此选项:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

相反,如果你想要阻止属性被序列化,如果它有默认值你可以做@HandPassant在注释中指出并应用DefaultValueAttribute (只有当值与你指定的默认值不同时才会被序列化) 。

Use this if you want that property to be serialized:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

Instead if you want to stop the property to be serialized if it has its default value you can do what @HandPassant pointed out in the comment and apply the DefaultValueAttribute (it'll be serialized only if the value is different from the default you specified).

更多推荐

本文发布于:2023-08-01 02:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1353798.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:放入   属性   文件   Designer   property

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!