0

I have too many method overloads for each method and I'm thinking how to make MyClass more easily understandable/usable to other developers. My ideas:

1.

make it partial class and new file name MyClassOldMethods.cs with all methods marked

[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]

this does not work, cause project is part of solution.

2.

Make old method overload as extension methods in other file in new static class. But I can't hide them from intellisense or can I?

Lots of existing code exist so the solution must be backward compatible. I have a feeling that this is wrong in a 1st place, but can it be done?

Edit: SO wants me to explain that How to hide public methods from intellisense is not a duplicate. it does not answer the question. i read it before posting. The answers clearly state that EditorBrowsableState does not hide anything in same solution and it has nothing to do with partitioning obsolete but somewhere used overloads. I want to know is it wrong to move instance mthods to extension methods.

Community
  • 1
  • 1
char m
  • 7,840
  • 14
  • 68
  • 117
  • 1
    Possible duplicate of [How to hide public methods from intellisense](http://stackoverflow.com/questions/9086136/how-to-hide-public-methods-from-intellisense) – stuartd Dec 08 '15 at 12:55
  • 1
    Your extension methods will be hidden from intllisense if you put them in a separate namespace. If you need an extension method you can always add `using some.namespace.with.extensions` and it will be available again. – Sergii Zhevzhyk Dec 08 '15 at 12:59
  • @stuartd: not duplicate. it does not answer the question. i read it before posting. The answers clearly state that EditorBrowsableState does not hide anything in same solution and it has nothing to do with partitioning obsolete but used overloads. – char m Dec 08 '15 at 13:20
  • @SergiiZhevzhyk: thanks. in your opinion would it be wrong to move instance methods to extension methods in different namespace? how about can there be any problems? the instance methods are thread safe. Will they be as extension methods? – char m Dec 08 '15 at 13:25
  • @matti it's not the best idea to use extension methods instead of instance methods and sometimes it's even impossible. What did you want to say by `I have too many method overloads for each method`? Could you provide a simple example? – Sergii Zhevzhyk Dec 08 '15 at 13:38
  • I have developed db-interface that can be used with different db-providers incrementally with a concept of dbrow evolving all the time when I been understanding more what I should do. Now I have Select, Insert, Update and Delete with all kinds of dbrow-concepts as parameters. When having 6 of each it is just a horrible mess. – char m Dec 08 '15 at 13:49
  • i agree that it's not good idea. What I would really like to do is have MyClass as partial class in 2 different namespaces. This is naturally impossible. But your answer is right so if u want to write short answer i accept it. – char m Dec 08 '15 at 13:50
  • @matti I've added the answer. I've added also some information about explicit implementation of interfaces which could be useful in your case. – Sergii Zhevzhyk Dec 08 '15 at 14:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/97297/discussion-between-sergii-zhevzhyk-and-matti). – Sergii Zhevzhyk Dec 08 '15 at 14:38

1 Answers1

0

Extension methods will be hidden from Intellisense if they are in a separate namespace which is defined among the using namespaces. If you need an extension method you can always add using some.namespace.with.extensions and it will be available again. This approach should be used wisely and extension methods should be used where they are appropriate. ReSharper doesn't use this rule and shows all possible extension methods from referenced libraries.

If a class implements many interfaces and there is no need to show all implemented methods, you can use the explicit implementation, for example:

public class SomeClass : SomeInterface
{
    void SomeInterface.SomeInterfaceMethod()
    {
         // ... some code ...
    }
}

When you check all methods of the class, SomeInterfaceMethod will not be shown unless the class is cast to the SomeInterface type.

Sergii Zhevzhyk
  • 4,074
  • 22
  • 28