3

I created class MyToolStrip:ToolStrip{}. My project already has about 60 toolstrip instances.

Is there a way (except signature find/replace) to:

  1. Force all my created forms to use MyToolStrip instead ToolStrip?
  2. Force future MyToolStrip usage instead of ToolStrip (compiler warning is good enough but not the best)?

I believe there's no correct way neither to mark ToolStrip Obsolete nor to "override" or hide system class. So what is best practice? Thanks.

John Smith
  • 185
  • 1
  • 8
  • 1
    `Force future MyToolStrip usage instead of ToolStrip` - you may want to consider code analysis rule. http://blogs.msdn.com/b/codeanalysis/archive/2010/03/26/how-to-write-custom-static-code-analysis-rules-and-integrate-them-into-visual-studio-2010.aspx – YK1 Jul 02 '13 at 19:26
  • Too bad it doesn't rely on oop paradigm or at least compiler directives, but that's close enough, thanks! BTW, found VS2008 integration example: http://blog.tatham.oddie.com.au/2010/01/06/custom-code-analysis-rules-in-vs2010-and-how-to-make-them-run-in-fxcop-and-vs2008-too/ – John Smith Jul 02 '13 at 23:46

1 Answers1

2

Is there a way (except signature find/replace) to force all my created forms to use MyToolStrip instead ToolStrip?

Not that I can think of - if your forms use a ToolStrip control there's no way to "inject" your control in its place. Even if you tried to hide the standard controls with clever #using aliases, the designers by default add the full namespace to control declarations:

private System.Windows.Forms.ToolStrip toolStrip1;

Is there a way (except signature find/replace) to force future MyToolStrip usage instead of ToolStrip (compiler warning is good enough but not the best)?

Again, not that I can think of. If you had control over ToolStrip you could matrk it as [Obsolete] which would cause a compiler warning or error (depending on how you want to use it) but since it's a framework class you don't have that luxury.

IMHO 60 instances isn't too many to change via Find/Replace...

D Stanley
  • 149,601
  • 11
  • 178
  • 240