What is the preferred naming convention for Func method parameters?

后端 未结 3 2287
时光取名叫无心
时光取名叫无心 2021-02-07 00:19

I admit that this question is subjective but I am interested in the view of the community. I have a cache class that takes a cache loader function of type Func

3条回答
  •  自闭症患者
    2021-02-07 00:55

    There are precedents for using a noun in the Framework, e.g.

    Enumerable.Average(this IEnumerable source, Func selector)
    
    Enumerable.Count(this IEnumerable source, Func predicate)
    
    Enumerable.GroupBy(this IEnumerable source, Func keySelector, Func elementSelector)
    
    ConcurrentDictionary.GetOrAdd(TKey key, 
                Func valueFactory);
    

    The noun is often an appropriate verb with an agentive suffix.

    In your example I would use something like loader or possibly valueFactory. I personally don't like cacheLoader because presumably it's the caller rather than the delegate that does the work of inserting in the cache.

提交回复
热议问题