类名不明确

发布于 2024-08-30 23:21:22 字数 175 浏览 3 评论 0原文

如果有一个新项目(ProjNew),我想在其中放置其他项目(ProjOld)上的几个类。

问题是我想维护标记为“已过时”的旧类,以避免运行我的所有项目并检查它们是否使用它。

但这样可能会引发不明确的类名错误,因为我没有按名称空间显式调用。

有没有办法说明在不明确的情况下使用过时的程序集?

If have a new project (ProjNew ) where I want to put several classes that are on other project (ProjOld).

The problem is I want to maintain the old classes marked with Obsolete to avoid running all my projects and check if they using it.

But in that way this may throw a ambiguous class name error because I didn't explicitly call by namespace.

Is there a way to say in the obsolete what assembly to use in ambiguity case?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

清风不识月 2024-09-06 23:21:22

目前还不完全清楚你在问什么,但无论如何我都会尝试一下。

假设您有两个 DLL,old.dll 和 new.dll,它们都有一个类型为 C 的命名空间 N。您可以这样做:

csc /r:NEW=new.dll /r:OLD=old.dll foo.cs

然后在 foo.cs 中您可以说

extern alias NEW;
extern alias OLD;
class D : NEW::N.C { }
class E : OLD::N.C { }

D 将从 new 中的 NC 继承。 dll中,E会继承old.dll中的NC。

这能解决你的问题吗?

It is not entirely clear what you're asking, but I'll give it a try anyway.

Suppose you have two DLLs, old.dll and new.dll, both of which have a namespace N with a type C. You can do this:

csc /r:NEW=new.dll /r:OLD=old.dll foo.cs

and then in foo.cs you can say

extern alias NEW;
extern alias OLD;
class D : NEW::N.C { }
class E : OLD::N.C { }

and D will inherit from the N.C in new.dll, E will inherit from the N.C in old.dll.

Does that solve your problem?

天赋异禀 2024-09-06 23:21:22

我不确定我是否完全理解你的问题,但这可能会有所帮助。您可以使用Using指令来明确要使用哪个类。一个例子:
使用 ClassA = OldAssembly.ClassA;

任何对 ClassA 的引用都将引用 OldAssembly。

I'm not sure if I entirely understand your question, but this may help. You can use a Using directive to clarify which class to use. An example:
using ClassA = OldAssembly.ClassA;

Any references to ClassA will then refer to OldAssembly.

帅冕 2024-09-06 23:21:22

您可以将类创建为部分类并标记您需要废弃的方法。

这将允许您将类划分为多个文件,并且仍然使用相同的类名。

You could create the classes as partial classes and mark the methods you need to be obsolete.

This would allow you to divide your classes up into multiple files and still use the same class name.

第七度阳光i 2024-09-06 23:21:22

使用 System.ObsoleteAttribute 标记您的类

http://msdn.microsoft.com/en-us/library/system.obsoleteattribute.aspx

using System;

class Program
{
    static void Main()
    {
        MethodA();
    }

    [Obsolete("Use MethodB instead")]
    static void MethodA()
    {
    }

    static void MethodB()
    {
    }
}

Mark your classes with System.ObsoleteAttribute

http://msdn.microsoft.com/en-us/library/system.obsoleteattribute.aspx

using System;

class Program
{
    static void Main()
    {
        MethodA();
    }

    [Obsolete("Use MethodB instead")]
    static void MethodA()
    {
    }

    static void MethodB()
    {
    }
}
稚然 2024-09-06 23:21:22

好的。看来,如果我将同一个类添加到另一个名称空间,则会出现歧义错误,这只是我在编译时发生的。
我担心它会在运行时发生,但我测试了一下,没有问题。

谢谢

OK. It seems that if i add the same class to another namespace the ambiguos error it's just i happen in compile time.
I was afraid that it happen in run time to, but i test it and there was no problem.

Thanks

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