Static classes with identical names and namespaces into different referenced projects #1722
Replies: 5 comments
-
Using directives allow specifying an alias, explicitly to work around this issue. I'd conjecture that the reason for method resolution not doing this disambiguation is because it would introduce inconsistency. If both methods declared |
Beta Was this translation helpful? Give feedback.
-
Such a conflict is extremely undesirable. When it exists, switching back and forth in the same file should be minimized. A good design will not require extern aliases. |
Beta Was this translation helpful? Give feedback.
-
@tannergooding @jnm2 The real situation looks like:
namespace AnyLibrary
{
public static class AnyExtensions
{
public static T Method_A<T>(this T o) => ... ;
public static T Method_B<T>(T o) => ... ;
public static T Method_C<T>(this T o) => ... ;
public static T Method_D<T>(T o) => ... ;
}
}
namespace AnyLibrary
{
public static class AnyExtensions
{
public static T Method_A<T>(this T o) => ... ;
public static T Method_B<T>(T o) => ... ;
}
} and not require the external dependency, namespace AnyLibrary
{
public static class AnyExtensions
{
public static T Method_C<T>(this T o) => ... ;
public static T Method_D<T>(T o) => ... ;
}
} contains the external dependency
x.Method_A()
AnyExtensions.Method_A(x)
AnyExtensions.Method_B(x)
x.Method_C()
AnyExtensions.Method_C(x)
AnyExtensions.Method_D(x) But currently situation looks very strange
x.Method_A()
x.Method_C() but can't use the same methods via class name AnyExtensions.Method_A(x)
AnyExtensions.Method_C(x)
AnyExtensions.Method_C(x)
AnyExtensions.Method_D(x) but can't AnyExtensions.Method_A(x)
AnyExtensions.Method_B(x) If a compiler can resolve this path conflict for implicit extension methods call [ |
Beta Was this translation helpful? Give feedback.
-
@CyrusNajmabadi Can we reopen when conversion to discussion fails so that it doesn't appear that the issue is being rejected without a response? |
Beta Was this translation helpful? Give feedback.
-
:( |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Scenario
Try to extend by new methods a existing static class from another referenced library (project)
Steps to reproduce
Create Project B and add into references Project A
Add into Project B a static class with the same name and namespace but another methods
x.Method_A()
but not possible likeAnyExtensions.Method_A(x)
. Seems thatshould be allowed too by compiler because it is possible to resolve a path conflict by method names.
Beta Was this translation helpful? Give feedback.
All reactions