C# 默认范围解析
我继承了 ac# 类“Button”(我无法更改),它与 BCL 类“Windows.Forms.Button”冲突。 通常情况下,我会很乐意去:
MyPackage.MyClass.Button;
但是有大量或对此类的引用,这需要重新输入,这很痛苦。
有没有办法让编译器(链接器?)默认使用 Button 的自定义版本而不是 BCL 版本?
I have inherited a c# class 'Button' (which I can't change) which clashes with the BCL class 'Windows.Forms.Button'. Normally, Id be very happy to go:
MyPackage.MyClass.Button;
But there are a large number or references to this class which is a pain to have to re-type.
Is there any way to get the compiler (linker?) to default to using the customised version of Button over the BCL version?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将其添加到文件顶部:
现在您可以使用不同的名称引用您的自定义按钮。 如果您在同一文件中的任何位置使用 Stock 按钮,则可能需要对 Stock 按钮执行类似的操作。
Add this to the top of the file:
Now you can reference your custom button using a distinct name. You may need to do something similar for the stock button if you use that anywhere in the same file.
如果您想默认使用它,请替换
为
如果您这样做,则需要完全限定 Windows.Forms 中的所有按钮。
或者,如果您愿意,您可以为命名空间添加别名
或为按钮添加别名
if you want to use it by default, replace
with
If you do that, you'll need to fully qualify all the buttons from Windows.Forms.
Or, if you want to, you can alias the namespace
Or alias the button
您可以从代码顶部删除
using Windows.Forms;
。 这当然意味着您必须专门引用所有 Windows.Forms 项目。You could remove
using Windows.Forms;
from the top of the code. That would of course mean that you would have to reference all Windows.Forms items specifically.看来我可以执行以下操作:
有效,并且它保留代码中对 Button 的所有引用。 尽管我不想走这条路,因为使用哪个按钮仍然不明确(至少对读者来说)。
It appears that I can do the following:
works and it preserves all references within the code to Button. Although Im tempted not to go down this route as it is still ambiguious (at least to the reader) which Button is being used.
你至少可以通过“使用”让它少一点痛苦/罗嗦:
然后你可以说:
You can at least make it a small bit less painful/wordy with "using":
then you can say: