0

a part of the framework we are working with has some extension methods that we would like to replace for debug reasons. While Simply replacing these in the code would be a viable option, I was wondering if we could to it with a "using" statement in the top of our c# files, rather than changing back and forth on each line where we use it.

While using normally works to solve conflicting names for classes in different namespaces, I can't find a way to solve this for extension methods, as this practically is just a reference to a static method. Not including the namespace with the original extension method is not an option.

Hope this makes sense, and that you people have any good solutions :)

Thanks / Jannek

Jannek
  • 94
  • 1
  • 5
  • Would be nice if you could provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – MakePeaceGreatAgain Aug 08 '18 at 13:52
  • i dont see how using = makes sense with extension methods...since the extension methods arent called by their namespace...they are called as if they are part of the object – Ctznkane525 Aug 08 '18 at 13:54
  • 1
    @Ctznkane525 The reverse is true. The namespaces currently in scope are precisely what determine whether or not an extension method can be called, and which one is called if there are multiple in scope. – Servy Aug 08 '18 at 13:56
  • sounds like you misunderstand what im saying @servy because i dont disagree with what you said – Ctznkane525 Aug 08 '18 at 13:57
  • @Ctznkane525 So if you're aware that the namespaces included via usings determine whether an extension method can be called, and which one is called if there are multiple, why did you say that it's irrelevant when dealing with extension methods? – Servy Aug 08 '18 at 13:58
  • @Servy If multiple namespaces are in scope, how does it determine what method to use? both namespaces are added with using, the code using the extension itself is in its own namespace. – Jannek Aug 08 '18 at 14:08
  • @MoreOrLessYou yes that does work :) not sure if there is other solutions to this. But otherwise feel free to post an answer. (or should I close this down? not sure what consensus is) Edit: sorry didn't see this was the same as the answer below. – Jannek Aug 08 '18 at 14:11
  • 2
    @Jannek There's a complex set of rules to define which of the methods is "closer", and should be used. It's defined in the specs. – Servy Aug 08 '18 at 14:12

0 Answers0