Using Action dictionaries instead of switch statements

后端 未结 4 1530
庸人自扰
庸人自扰 2020-12-09 03:13

I\'m just reviewing some of my old code (have some spare time), and I noticed a rather lengthy switch statement. Due to gaining new knowledge, I have since refactored it in

4条回答
  •  忘掉有多难
    2020-12-09 03:42

    This approach is excellent.

    I use it with more than just Action. It's also quite effective for filters and selectors. Something like:

    var filters = new Dictionary>()
    {
        // ...
    };
    
    var query = entities.Where(filters["X"]);
    

提交回复
热议问题