Windows Forms inheritance problem
-
As it's my first post here I should probably say "Hello" :-) In WinForms application I'm developing I'd like to have a Panel (let's name it "controlContent"), that should be editable in inherited classes (I want to add controls to it) and second Panel, that will have some buttons common to all controls in this hierarchy. The problem is that when I do it the simplest way - by setting controlContent to be protected - StyleCop says, that field should not be protected, create property instead. Well obviously he's right. But when I create what he want's I don't have access through Visual Studio designer to the Panel. And of course I don't wan't to write controls' layout manually. Did anyone have similar issue? How can I solve it? (I was searching web, but either I'm asking google wrong questions or answer isn't there).
-
As it's my first post here I should probably say "Hello" :-) In WinForms application I'm developing I'd like to have a Panel (let's name it "controlContent"), that should be editable in inherited classes (I want to add controls to it) and second Panel, that will have some buttons common to all controls in this hierarchy. The problem is that when I do it the simplest way - by setting controlContent to be protected - StyleCop says, that field should not be protected, create property instead. Well obviously he's right. But when I create what he want's I don't have access through Visual Studio designer to the Panel. And of course I don't wan't to write controls' layout manually. Did anyone have similar issue? How can I solve it? (I was searching web, but either I'm asking google wrong questions or answer isn't there).
StyleCop is right - field members should be private, but this is one of those circumstances where the only sensible way to do what you want is to set the field to protected. Just go with that and ignore the StyleCop rule.
"An eye for an eye only ends up making the whole world blind"
-
StyleCop is right - field members should be private, but this is one of those circumstances where the only sensible way to do what you want is to set the field to protected. Just go with that and ignore the StyleCop rule.
"An eye for an eye only ends up making the whole world blind"
Yeah. That's what I'm doing right now. I was just wondering if there's some workaround. Either way thanks for your answer. And I'll still be waiting, maybe someone knows something :-)