Tuesday, August 19, 2008

Life is fun when you are slow

public void IfTrueRunMethod(Func<Boolean> trueMethod, Action action)
{
  if(trueMethod())
  {
    action();
  }
}
Just something I made for the hell of it to remove:
if(someClass != null && someClass.Property == "hi")
{
  SomeMethod();
}
This can be reduced to one line... yay!
IfTrueRunMethod(() => { someClass != null && someClass.Property == "hi" }, () => SomeMethod());
You could even transform the first part into a method if you want:
IfTrueRunMethod(() => TrueMethod(someClass), () => SomeMethod());
Weeeee!
using System;
using System.Linq;

No comments: