开发者

Ambiguous class name

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 nam开发者_开发知识库espace.

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


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?


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.


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()
    {
    }
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜