I just received the following compile time error in C#:
Ambiguous invocation:
string GetDescription(this LibA.enum_contact) in LibA
string GetDescription(this LibB.enum_contact) in LibB
It is clear what it means, but since I need to use both libraries and they are closed source, I wonder what a proper workaround would be. I can think of the following in the using code:
- Split source file into two partials, but not sure this will not yield the same error (are using directives in scope per file, or per code unit?)
- Create a wrapper for these extension methods
- Call the extension method with a fully qualified name as normal method
- or, in addition, redefine the class name with a
using
-directive to make this less a pain
Neither of these seem to be fully satisfactory. In some OO languages, it is possible to limit to some granularity what you accept, or, for instance in Eiffel, to rename a method when you import it and there is a name collision. I would love to be able to do:
using LibA rename ClassA.GetDescription to GetMyDescription
using LibB rename ClassB.GetDescription to GetDescriptionB
But I don't believe I've seen such a method for C# up until 6.0. I.e., you can rename a classname, but not a method name.
Does anybody have a better idea than the suggestions above?