How to disable designer in derived classes in following generations
Asked Answered
M

2

8

In order to disable component designer in classes it is simple to add just [System.ComponentModel.DesignerCategory("")] attribute to it, however it does not work for any classes derived from this class in any generation. E.g:

[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

This happens, of course, in any other generations and permutations. E.g.

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

Does anybody ever tried to get rid of it? Why component model tries to add designer support even if it explicitely disabled in first generation?

Thank you

Millihenry answered 24/1, 2012 at 9:45 Comment(2)
It is very unclear exactly in which assemblies these classes live and whether or not they are part of the solution. The toolbox' AutoPopulate setting takes precedence.Kohler
this is not mention. either f base and derived classes in the same assembly or they are in different assemblies behaviour is the same (only base class [one directly derived from ServiceBase] has no designer on it)Millihenry
M
8

The reason for such behaviour is cached referenced assemblies. To solve it, remove reference to the assembly contained base server with attribute and add it again. In this case Visual Studio rebuild project and will not define default editor to derrived class.

Millihenry answered 25/1, 2012 at 16:25 Comment(1)
I had the same problem, and this worked for me. My base class was derived from System.ComponentModel.Component and I had to remove the reference to System, and then add it again. All the derived classes now open with the code editor by default. Thanks!Lindell
S
0

"Attribute inheritance" at first struck me as odd, as I always thought that attributes weren't inherited; after checking learn.microsoft.com I discovered that that doesn't have to be the case - attributes may have Inherited = true, so thanks to you for helping me broaden my knowledge :-)

Additionally, I also had to remove a bunch of <SubType>Component</SubType> entries from the .csproj file

Solorzano answered 26/9, 2017 at 15:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.