I recently used extension methods to help make my code more free, but I constantly encounter situations where I cannot limit the exposure of the functionality that I created as I would like.
Let's say I have a code like this (a fully compiled example):
var liveSet = allitems.Where(x => x.Status == Status.Live).Select(x => x.Name);
var deadSet = allitems.Where(x => x.Status == Status.Dead).Select(x => x.Name);
var zombieSet = allitems.Where(x => x.Status == Status.Neither).Select(x => x.Name);
I would like to do it more freely, and stop repeating:
var liveSet = allitems.SelectNameWhere(x => x.Status == Status.Live);
...
But I consider this a helper method, not a true extension, so I would like to limit its use in the same way as I can a private method:
private static IEnumerable<string> SelectNameWhere(
this IEnumerable<Element> items,
Func<Element, bool> predicate)
...
, , , , . , , ... , , , , , , , :
var liveSet = SelectNameFrom(allItems, x => x.Status == Status.Live);
...
, , , , . , ?