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
Written by Emanuele
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#.net
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#