0
namespace common
{
   public static class MyExtensions
    {
        public static string stringextmethod(this string uri)
        {

        }
   }
}

namespace commonCore
{
   public static class MyExtensions
    {
        public static string stringextmethod(this string uri)
        {

        }
   }
}

I have a class that refer both namespaces above, now when I try to use 'stringextmethod' I am getting an error 'Overload resolution failed..' How can I use extension method 'stringextmethod' from 'common' namespace only.

Bobr
  • 155
  • 1
  • 1
  • 7
  • 1
    You could only use `Using Common` and avoid `Using commonCore` in the relevant code files. – Jens Jul 01 '15 at 10:14
  • relavant code has huge functionality and refers both namespaces, so is there any way that I can use 'Using' at specific required statement. – Bobr Jul 01 '15 at 10:16
  • You could call the extension method directly and include the namespace in the call like `common.stringextmethod(whatever)` instead of using it as an extension. – Jens Jul 01 '15 at 10:18
  • 1
    @Jens He has to include the class name... `common.MyExtensions.stringextmethod(whatever)` – xanatos Jul 01 '15 at 10:24
  • @xanatos true, somehow missed that, but the base idea, to call the method as a function with proper qualification, instead of as an extension was still valid ;-) – Jens Jul 01 '15 at 10:51
  • @Jens Yep... If you want to be cruel, you could even create your own extension method in your "current" namespace that uses one of the two extension methods :-) "current" namespace should triumph over "external" namespace collisions (that is the solution proposed here http://stackoverflow.com/a/18702605/613130) – xanatos Jul 01 '15 at 10:55

0 Answers0