Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
240 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...