/// /// Generic Enum.Parse implementation. /// /// The enumeration type to parse to. /// String value to parse. /// Default value when conversion fails. /// The parsed result or the default provided when parsing failed. public static TEnum ToEnum (this string strEnumValue, TEnum defaultValue) { if (!Enum.IsDefined(typeof(TEnum), strEnumValue)) return defaultValue; return (TEnum)Enum.Parse(typeof(TEnum), strEnumValue); } /// /// Invoke passed in action synchronously on the GUI thread of this item. /// /// The control. /// Action that will be performed on the GUI thread. public static void InvokeOnGui(this Control me, Action action) { if (me.InvokeRequired) me.Invoke(action); else action(); } /// /// Invoke passed in action asynchronously on the GUI thread of this item. Note: If this method is called /// on the GUI thread, the action will be performed synchronously. If it is called from another thread, it /// is invoked asynchronoulsly. /// /// The control. /// Action that will be performed on the GUI thread. public static void BeginInvokeOnGui(this Control me, Action action) { if (me.InvokeRequired) me.BeginInvoke(action); else action(); }