What is the preferred naming convention for Func method parameters?

后端 未结 3 549
鱼传尺愫
鱼传尺愫 2021-02-07 00:45

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:52

    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.

提交回复
热议问题