8

为了在类中禁用组件设计器,只需向其添加 [System.ComponentModel.DesignerCategory("")] 属性很简单,但是它不适用于任何一代中从此类派生的任何类。例如:

[System.ComponentModel.DesignerCategory("")]
public class A:ServiceBase { } //Designer is disabled here

public class B:A {} //Designer is enabled here

[System.ComponentModel.DesignerCategory("")]
public class B:A {} //Designer is enabled here too

[System.ComponentModel.DesignerCategory("Code")]
public class B:A {} //Designer is enabled even here

当然,这发生在任何其他代和排列中。例如

//Whatever attribute here
public class C:B {} //Designer is enabled here

有没有人试图摆脱它?为什么组件模型即使在第一代中明确禁用也会尝试添加设计器支持?

谢谢

4

2 回答 2

8

这种行为的原因是缓存的引用程序集。要解决此问题,请删除对包含具有属性的基本服务器的程序集的引用并再次添加它。在这种情况下,Visual Studio 重建项目并且不会为派生类定义默认编辑器。

于 2012-01-25T16:25:31.320 回答
0

“属性继承”一开始让我觉得很奇怪,因为我一直认为属性不是继承的。检查docs.microsoft.com后,我发现情况并非如此 - 属性可能有Inherited = true,所以感谢您帮助我拓宽知识 :-)

<SubType>Component</SubType>此外,我还必须从 .csproj 文件中删除一堆条目

于 2017-09-26T15:04:45.813 回答