using System; namespace mRemoteNG.Tools { public static class Extensions { public static Optional Maybe(this T value) { return new Optional(value); } public static Optional MaybeParse(this T value, Func parseFunc) { try { return new Optional(parseFunc(value)); } catch { return new Optional(); } } /// /// Throws an if the given value is /// null. Otherwise, return the value. /// /// /// /// /// The name of the argument /// public static T ThrowIfNull(this T value, string argName) { if (value == null) throw new ArgumentNullException(argName); return value; } /// /// Throws an if the value /// is null or an empty string. Otherwise, returns the value. /// /// /// public static string ThrowIfNullOrEmpty(this string value, string argName) { if (string.IsNullOrEmpty(value)) throw new ArgumentException("Value cannot be null or empty", argName); return value; } } }