Ambiguous class name

If you have a new project (ProjNew), where I want to put several classes in another project (ProjOld).

The problem is that I want to keep the old classes marked as "Deprecated" in order to avoid starting all my projects and see if they use it.

But in this way, it can cause an ambiguous class name error, because I did not explicitly call the namespace.

Is there any way to tell in outdated which assemblies to use in case of ambiguity?

+4
source share
5 answers

It’s not entirely clear what you are asking, but I’ll try anyway.

Suppose you have two DLLs, old.dll and new.dll, each of which has an N namespace of 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::NC { } class E : OLD::NC { } 

and D inherits from NC in new.dll, E inherits from NC in old.dll.

Does your problem solve?

+4
source

I'm not sure I fully understand your question, but that might help. You can use the Using directive to specify which class to use. Example: using ClassA = OldAssembly.ClassA;

Any references to ClassA will refer to OldAssembly.

+2
source

You can create classes as partial classes and mark the methods you need for obsolescence.

This will allow you to split classes into multiple files and still use the same class name.

+1
source

Mark your System.ObsoleteAttribute classes

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

OK It seems that if I add the same class to a different namespace, the ambiguos error will just happen at compile time. I was afraid that this would happen at runtime, but I was testing it and there were no problems.

thanks

0
source

Source: https://habr.com/ru/post/1308379/


All Articles