Yodiwo.DebugEx.Assert C# (CSharp) Méthode

Assert() private méthode

private Assert ( Exception ex, bool reportIt = true, [ filePath = "", [ lineNumber, [ method = "" ) : void
ex System.Exception
reportIt bool
filePath [
lineNumber [
method [
Résultat void
        public static void Assert(Exception ex, bool reportIt = true, [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0, [CallerMemberNameAttribute] string method = "")
        {
            if (LogLevel > eTraceType.Critical)
                return;

            var stack = ex?.StackTrace;
            var failure = new YIncident() { IsAssert = true };
            failure.StackTrace = ex != null ? new StackTrace(ex, true) : null;

            while (ex != null)
            {
                failure.Messages.Add(ex.Message);
                ex = ex.InnerException;
            }
            var msg = "Assert failed: " + Environment.NewLine
                + string.Join(Environment.NewLine, failure.Messages) + Environment.NewLine
                + "StackTrace:" + stack;

            Debug.Assert(false, msg);
            TraceError(msg, filePath: filePath, lineNumber: lineNumber, method: method);

            if (reportIt)
                ThrowYIncident?.Invoke(failure);
        }

Same methods

DebugEx::Assert ( Exception ex, string Error_Message, bool reportIt = true, [ filePath = "", [ lineNumber, [ method = "" ) : void
DebugEx::Assert ( bool Condition, string Error_Message, bool reportIt = true, bool StackTrace = true, [ filePath = "", [ lineNumber, [ method = "" ) : void
DebugEx::Assert ( string Error_Message, bool reportIt = true, bool StackTrace = true, [ filePath = "", [ lineNumber, [ method = "" ) : void

Usage Example

Exemple #1
0
        //--------------------------------------------------------------------------------------------------------------------------------------
        public bool RemoveEventHandler <T>(EventCb <T> cb)
        {
            //null check
            if (cb == null)
            {
                return(false);
            }

            //Get route
            var evType = typeof(T);

            lock (_ActiveRoutes)
            {
                var allRoutesForType = _ActiveRoutes.TryGetOrDefault(evType);

                //check if handlers are registered for this event type
                if (allRoutesForType == null)
                {
                    DebugEx.Assert("no such event found registered");
                    return(false);
                }

                //Remove from route
                var removed = allRoutesForType.RemoveWhere(h => Object.Equals(h.Cb, cb)) > 0;

                //check if this event type has any other handlers, otherwise remove the type as well
                if (allRoutesForType.Count == 0)
                {
                    _ActiveRoutes.Remove(evType);
                }

                //return if something has been removed or not
                return(removed);
            }
        }
All Usage Examples Of Yodiwo.DebugEx::Assert