我有一个自定义控件,我已将其放在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).
更多推荐
发布评论