If
Executes a function if a given predicate is true
Source
public static T If<T>(this T val, Func<T,bool> predicate, Func<T, T> func)
{
if(predicate(val))
{
return func(val);
}
return val;
}
Example
var lang = GetLanguage();
lang.If(l=>l.Name!="Spanish", l=> MessageBox.Show("Non-spanish language!"));