C# 默认范围解析

发布于 2024-07-06 13:13:47 字数 224 浏览 4 评论 0原文

我继承了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

黑寡妇 2024-07-13 13:13:47

将其添加到文件顶部:

using MyButton = MyPackage.MyClass.Button;

现在您可以使用不同的名称引用您的自定义按钮。 如果您在同一文件中的任何位置使用 Stock 按钮,则可能需要对 Stock 按钮执行类似的操作。

Add this to the top of the file:

using MyButton = MyPackage.MyClass.Button;

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.

如梦亦如幻 2024-07-13 13:13:47

如果您想默认使用它,请替换

using Windows.Forms;

using MyPackage.MyClass;

如果您这样做,则需要完全限定 Windows.Forms 中的所有按钮。

或者,如果您愿意,您可以为命名空间添加别名

using My = MyPackage.MyClass;
//... then
My.Button b = ...

或为按钮添加别名

using MyButton = MyPackage.MyClass.Button;

if you want to use it by default, replace

using Windows.Forms;

with

using MyPackage.MyClass;

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

using My = MyPackage.MyClass;
//... then
My.Button b = ...

Or alias the button

using MyButton = MyPackage.MyClass.Button;
享受孤独 2024-07-13 13:13:47

您可以从代码顶部删除 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.

厌倦 2024-07-13 13:13:47

看来我可以执行以下操作:

using Button = MyPackage.MyClass.Button;

有效,并且它保留代码中对 Button 的所有引用。 尽管我不想走这条路,因为使用哪个按钮仍然不明确(至少对读者来说)。

It appears that I can do the following:

using Button = MyPackage.MyClass.Button;

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.

旧伤还要旧人安 2024-07-13 13:13:47

你至少可以通过“使用”让它少一点痛苦/罗嗦:

using MPMC = MyPackage.MyClass;

然后你可以说:

MPMC.Button

You can at least make it a small bit less painful/wordy with "using":

using MPMC = MyPackage.MyClass;

then you can say:

MPMC.Button
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文