Reputation: 11426
Since there is nothing the C# language to prevent anywhere in a class calling a private method from within that class, is there a standard naming convention for methods which are only ever to be called by another exclusive method(s)?
Why? So someone else does not accidentally call the method (if they are aware of the convention).
For example when I have recursive method I often have another method which I want to be the exclusive caller of the method, then everyone should call that method not my recursive method directly. For example:
private void FindPathToNode(Node currentNode, List<Node> visitedNodes, List<Node> path, int targetId, ref bool found)
{
...
FindPathToNode(node, visitedNodes, path, targetId, ref found);
}
private void FindPathToNode(Node startNode, int targetId)
{
var visitedNodes = new List<Node>();
var path = new List<Node>();
var found = false;
FindPathToNode(startNode, visitedNodes, path, targetId, ref found);
}
I like the idea of leading underscore as in other language it indicates "privateness" e.g. Python (though there it only indicates private at the class level).
private void _FindPathToNode(Node currentNode, List<Node> visitedNodes, List<Node> path, int targetId, ref bool found)
But is there already a widely used convention?
Upvotes: 0
Views: 99
Reputation: 64628
The closest I can find, the naming convention proposed by Microsoft is Core
.
Example:
public Add(Item item)
{
AddCore(item);
}
public Replace(Item item1, Item item2)
{
RemoveCore(item1);
AddCore(item2);
}
See also this related question: More private than private? (C#)
Upvotes: 1