//================================================================================================== /// <exception cref="ArgumentNullException" /> /// <exception cref="HOperationFailedException" /> public static void Do(Action action) { HArgChecking.VerifyNotNull(action); try { action(); } catch (Exception e) { throw HOpFailedExceptionCreator.Create(e); } }
/// <exception cref="ArgumentNullException" /> public static bool Try(Action action, out Exception err) { HArgChecking.VerifyNotNull(action); try { action(); } catch (Exception e) { err = e; return(false); } err = null; return(true); }
public static bool IsOneOf([HOptional] object obj, params object[] objects) { HArgChecking.VerifyNotNull(objects); foreach (object o in objects) { if (object.Equals(o, obj)) { return(true); } } return(false); }
/// <exception cref="ArgumentNullException" /> public static bool Try(ref Exception err, Action action) { HArgChecking.VerifyNotNull(action); try { action(); } catch (Exception e) { if (err != null) { err = e; } return(false); } return(true); }
/// <exception cref="ArgumentNullException" /> public static string ComposeMessage(Exception e, bool withStackTrace) { HArgChecking.VerifyNotNull(e); string baseMessage = e.Message != "" ? string.Format("{0}: {1}", e.GetType(), e.Message) : e.GetType().ToString(); if (!withStackTrace) { return(baseMessage); } return(baseMessage + (e.StackTrace != null ? Environment.NewLine + e.StackTrace : "")); }
/// <exception cref="ArgumentNullException" /> public static StringBuilder ConvertAsText(StringBuilder multilineBld) { HArgChecking.VerifyNotNull(multilineBld); var sb = new StringBuilder(); for (int i = 0; i < multilineBld.Length; i++) { char ch = multilineBld[i]; if (ch == '\n') // LF { sb.AppendLine(); } else if (ch != '\r') // CR { sb.Append(ch); } } return(sb); }
/// <exception cref="ArgumentNullException" /> public static string ComposeChainedMessage(Exception e, bool withStackTrace, bool separateItems) { HArgChecking.VerifyNotNull(e); var sb = new StringBuilder(); for (var x = e; x != null; x = x.InnerException) { if (x != e) { sb.AppendLine(); if (separateItems) { sb.AppendLine(); } } if (e.InnerException != null) { sb.Append("* "); } sb.Append(ComposeMessage(x, withStackTrace)); } return(sb.ToString()); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /// <exception cref="ArgumentNullException" /> public static string ConvertAsText(string multilineStr) { HArgChecking.VerifyNotNull(multilineStr); return(HTextBuilder.ConvertAsText(multilineStr).ToString()); }
//-------------------------------------------------------------------------------------------------- /// <exception cref="ArgumentNullException" /> public static string FormatAsText(string multilineStrFmt, params object[] parameters) { HArgChecking.VerifyNotNull(multilineStrFmt); HArgChecking.VerifyNotNulls(parameters); return(ConvertAsText(string.Format(multilineStrFmt, parameters))); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /// <exception cref="ArgumentNullException" /> public static StringBuilder ConvertAsText(string multilineStr) { HArgChecking.VerifyNotNull(multilineStr); return(ConvertAsText(new StringBuilder(multilineStr))); }