简体   繁体   中英

how to hide method overloads from intellisense and main class code file when project is part of VS2013 solution?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM