[フレーム]
Last Updated: February 25, 2016
·
611
· emadb

Actions as parameters

In most case actions are useful method parameters. Consider that you should execute some code in transaction. You can do like this:

With.Transaction(() => {
 // some code
});

Transaction is a static method of With class:

public class With
{
 public static void Transaction(Action<T> action)
 {
 using (Transaction t = new Transaction())
 {
 action();
 t.Complete();
 }
 }
}

Whit method can be reused and can be overloaded with collection of actions or/and action with different paramters

AltStyle によって変換されたページ (->オリジナル) /