Using “Hole in the Middle” pattern

前端 未结 1 473
广开言路
广开言路 2020-12-20 06:46


I just came across the \"Hole in the Middle\" pattern and think that I can use it to remove some repetitive code specially when I try to benchmark different methods and

1条回答
  •  臣服心动
    2020-12-20 07:40

    You can make a generic method and use a generic delegate:

    public static TResult PrePostMethod(Func someMethod, T1 a, T2 b)
    {
        Debug.Print("Pre");
    
        var result = someMethod(a, b);
    
        Debug.Print("Post");
    
        return result;
    }
    

    You'll need a separate generic overload for each number of parameters.

    0 讨论(0)
提交回复
热议问题