Exemple #1
0
//==================================================================================================

/// <exception cref="ArgumentNullException" />
/// <exception cref="HOperationFailedException" />
        public static void Do(Action action)
        {
            HArgChecking.VerifyNotNull(action);
            try { action(); }
            catch (Exception e)
            { throw HOpFailedExceptionCreator.Create(e); }
        }
Exemple #2
0
/// <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);
        }
Exemple #3
0
 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);
 }
Exemple #4
0
/// <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);
        }
Exemple #5
0
/// <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 : ""));
        }
Exemple #6
0
/// <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);
        }
Exemple #7
0
/// <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());
        }
Exemple #8
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <exception cref="ArgumentNullException" />
        public static string ConvertAsText(string multilineStr)
        {
            HArgChecking.VerifyNotNull(multilineStr);
            return(HTextBuilder.ConvertAsText(multilineStr).ToString());
        }
Exemple #9
0
//--------------------------------------------------------------------------------------------------

/// <exception cref="ArgumentNullException" />
        public static string FormatAsText(string multilineStrFmt, params object[] parameters)
        {
            HArgChecking.VerifyNotNull(multilineStrFmt);
            HArgChecking.VerifyNotNulls(parameters);
            return(ConvertAsText(string.Format(multilineStrFmt, parameters)));
        }
Exemple #10
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <exception cref="ArgumentNullException" />
        public static StringBuilder ConvertAsText(string multilineStr)
        {
            HArgChecking.VerifyNotNull(multilineStr);
            return(ConvertAsText(new StringBuilder(multilineStr)));
        }