using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Umbraco.Core { /// /// Extension methods for 'If' checking like checking If something is null or not null /// public static class IfExtensions { /// The if not null. /// The item. /// The action. /// The type public static void IfNotNull(this TItem item, Action action) where TItem : class { if (item != null) { action(item); } } /// The if true. /// The predicate. /// The action. public static void IfTrue(this bool predicate, Action action) { if (predicate) { action(); } } /// /// Checks if the item is not null, and if so returns an action on that item, or a default value /// /// the result type /// The type /// The item. /// The action. /// The default value. /// public static TResult IfNotNull(this TItem item, Func action, TResult defaultValue = default(TResult)) where TItem : class { return item != null ? action(item) : defaultValue; } /// /// Checks if the value is null, if it is it returns the value specified, otherwise returns the non-null value /// /// /// /// /// public static TItem IfNull(this TItem item, Func action) where TItem : class { return item ?? action(item); } } }