Пример #1
0
 public string Run()
 {
     return(fridayFeature.Execute(
                ifEnabled: () => "Thank goodness",
                ifDisabled: () => null
                ));
 }
Пример #2
0
            public int Calculate(int input)
            {
                var plus = plusTwo.Execute(
                    ifEnabled: () => 2,
                    ifDisabled: () => 0
                    );
                var times = timesFive.Execute(
                    ifEnabled: () => 5,
                    ifDisabled: () => 1
                    );

                return((input + plus) * times);
            }
            public T Execute <T>(Func <T> ifEnabled, Func <T> ifDisabled)
            {
                return(inner.Execute(IncrementOnException(ifEnabled), ifDisabled));

                Func <T> IncrementOnException(Func <T> func) => () =>
                {
                    try
                    {
                        return(func());
                    }
                    catch (Exception)
                    {
                        onException();
                        throw;
                    }
                };
            }