c# - 如何在后代中禁用派生类中的设计器

标签 c# visual-studio inheritance design-time componentmodel

为了在类中禁用组件设计器,只需向其添加 [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

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

谢谢

最佳答案

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

关于c# - 如何在后代中禁用派生类中的设计器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8984683/

相关文章:

c# - 按顺序将数组分配给类成员

c# - puppeetersharp 中的单页 PDF

c# - Winform 和用户控制 - C#

sql - 如何在 Visual Studio 中使用 SSDT 生成选择或插入表的脚本

C++ 坐标错误

c++ - 如何在控制台应用程序中定位提示?

c# - Visual Studio 扩展包是否支持异步操作

c++ - 仅包含基类 header 时访问派生类

Equals() 的 C++ 双重分派(dispatch)

javascript - 在这种情况下在 JavaScript 中实现继承 [更具体地说是 node.js]