views:

160

answers:

6

Hello

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?

A: 

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()
    {
    }
}
this. __curious_geek
Does this address the OPs need to have 2 classes with the same name? Can a class be marked as obsolete whilst having another class with the same name used in the same namespace? (by the looks of it, your example demonstrates marking a class member as obsolete, not the class itself)
Jamie Dixon
A: 

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.

Jamie Dixon
Partial classes do not cross assembly boundaries.
Eric Lippert
Ah! I didn't realise that but it makes sense. Cheers for the heads up Eric.
Jamie Dixon
+1  A: 

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.

CuriousCoder
A: 

Basicaly i have

MyNameSpace1.ClassA in one assembly and MyNameSpace2.ClassA in another assembly it's the same class.

And i have declarations like:

ClassA myClass; -> in here it throws a error because he cannot resolve what namespace to use if MyNameSpace1 or MyNameSpace2.

The partial

Pedro Dias
A: 

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

Pedro Dias
+1  A: 

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?

Eric Lippert