gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 18:32:29 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com