类名不明确
如果有一个新项目(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
目前还不完全清楚你在问什么,但无论如何我都会尝试一下。
假设您有两个 DLL,old.dll 和 new.dll,它们都有一个类型为 C 的命名空间 N。您可以这样做:
然后在 foo.cs 中您可以说
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:
and then in foo.cs you can say
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?
我不确定我是否完全理解你的问题,但这可能会有所帮助。您可以使用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.
您可以将类创建为部分类并标记您需要废弃的方法。
这将允许您将类划分为多个文件,并且仍然使用相同的类名。
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.
使用 System.ObsoleteAttribute 标记您的类
http://msdn.microsoft.com/en-us/library/system.obsoleteattribute.aspx
Mark your classes with System.ObsoleteAttribute
http://msdn.microsoft.com/en-us/library/system.obsoleteattribute.aspx
好的。看来,如果我将同一个类添加到另一个名称空间,则会出现歧义错误,这只是我在编译时发生的。
我担心它会在运行时发生,但我测试了一下,没有问题。
谢谢
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