Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

c# - Overwrite built in .NET class

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...