覆盖内置的.NET类 [英] Overwrite built in .NET class

查看:63
本文介绍了覆盖内置的.NET类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我从诸如System.Windows.Forms.Control之类的类继承并创建System.Windows.Forms.NewControl,有没有一种方法可以强制.NET将System.Windows.Forms.NewControl类用作System. Windows.Forms.Control,以便所有内置控件都使用我的System.Windows.Forms.NewControl?

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.

推荐答案

不,您不能做这样的事情. OO的思想是,遵循现有类的契约和行为编写代码的人们可以相信,该类将继续表现其设计方式,而不必担心用户的干扰.这不是像Ruby这样的动态语言.

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.

这篇关于覆盖内置的.NET类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆