I have a method that I want to access from only one method because it is very specific and could confuse the programmers if they “see” that method from the other parts of the class. On the other hand, for unit testing and for readability, I have to make that method.
Is there any trick to encapsulate further than usual?
Just to make sure my idea is clear: method A calls method B. I want intellisense to show method B only if I am in method A.
You can check the caller of the method, execute your method body only if the caller name matches (assuming you have only 1 method of that name, otherwise you have to check the arguments as well).
Not possible to hide this in intellisense though. Furthermore create a region in the class for the DO NOT USE method.
An alternative approach using Attributes
Rather than hard coding the method name, you can create a custom attribute and mark your method with it to indicate that you are allowing this caller to execute your
DoNotUseMethod().And in your class use the attribute as follows,