0

if i inherit from a class such as System.Windows.Forms.Control and create System.Windows.Forms.NewControl, is there a way of forcing .NET to use my System.Windows.Forms.NewControl class as System.Windows.Forms.Control so that all built in controlls use my System.Windows.Forms.NewControl?

ie. i would like to make some base changes to how controls work, and i would like those changes to be reflected in ALL controls without having to subclass every single control type.

i know that extension methods will not work for this as they need to be called explicitly, and i am looking to alter properties as well as methods.

bizzehdee
  • 20,289
  • 11
  • 46
  • 76
  • What you are describing is akin to [AOP](http://en.wikipedia.org/wiki/Aspect-oriented_programming), using some sort of method interception. – Robert Harvey Apr 05 '13 at 22:21
  • @RobertHarvey: That's not AOP; it's just some seriously sick and flawed shizzle. – Steven Apr 05 '13 at 22:32

1 Answers1

5

No, you cannot do anything like this. The idea behind OO is that people who write code adhering to the contract and behavior of an existing class can trust that the class will continue to behave how it's designed without worry about user interference. This isn't a dynamic language like Ruby.

Kirk Woll
  • 76,112
  • 22
  • 180
  • 195
  • so i would then have to create NewForm, NewLabel and so on, and implement my changes into each individual control? – bizzehdee Apr 05 '13 at 22:25
  • 1
    @bizzehdee As C# does not support multiple inheritance, yes, that’s your only option, unless you can encapsulate your functionality in a different way. – poke Apr 05 '13 at 22:27