/// <summary> /// Initializes a new instance of the <see cref="Stack" /> class from the specified instance. /// </summary> /// <param name="other"> /// The instance from which the new instance is to be initialized. /// </param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="other" /> is null. /// </exception> public Stack(Stack other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } Init(other.Message, other.Frames, other.Properties); }
/// <summary> /// Creates a SARIF Stack instance from a .NET StackTrace /// text representation (as returned by StackTrace.ToString()) /// </summary> /// <param name="stackTrace"></param> public static Stack Create(string stackTrace) { Stack stack = new Stack(); if (string.IsNullOrEmpty(stackTrace)) { return stack; } stack.Frames = new List<StackFrame>(); var regex = new Regex(StackFrame.AT + @"([^)]+\))(" + StackFrame.IN + @"([^:]+:[^:]+)" + StackFrame.LINE + @" (.*))?", RegexOptions.Compiled); foreach (string line in stackTrace.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)) { // at Type.Method() in File.cs : line X string current = line; var stackFrame = new StackFrame(); Match match = regex.Match(line); if (match.Success) { stackFrame.FullyQualifiedLogicalName = match.Groups[1].Value; if (!string.IsNullOrEmpty(match.Groups[2].Value)) { string fileName = match.Groups[3].Value; int lineNumber = int.Parse(match.Groups[4].Value); stackFrame.Uri = new Uri(fileName); stackFrame.Line = lineNumber; } } stack.Frames.Add(stackFrame); } return stack; }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionData" /> class from the supplied values. /// </summary> /// <param name="kind"> /// An initialization value for the <see cref="P: Kind" /> property. /// </param> /// <param name="message"> /// An initialization value for the <see cref="P: Message" /> property. /// </param> /// <param name="stack"> /// An initialization value for the <see cref="P: Stack" /> property. /// </param> /// <param name="innerExceptions"> /// An initialization value for the <see cref="P: InnerExceptions" /> property. /// </param> public ExceptionData(string kind, string message, Stack stack, IEnumerable<ExceptionData> innerExceptions) { Init(kind, message, stack, innerExceptions); }
private void Init(string kind, string message, Stack stack, IEnumerable<ExceptionData> innerExceptions) { Kind = kind; Message = message; if (stack != null) { Stack = new Stack(stack); } if (innerExceptions != null) { var destination_0 = new List<ExceptionData>(); foreach (var value_0 in innerExceptions) { if (value_0 == null) { destination_0.Add(null); } else { destination_0.Add(new ExceptionData(value_0)); } } InnerExceptions = destination_0; } }
public void Stack_CreateFromStackTrace() { var dotNetStack = new StackTrace(); Stack stack = new Stack(dotNetStack); // The .NET StackTrace.ToString() override must preserve a trailing NewLine // for compatibility reasons. We do not retain this behavior in ToString() // but provide a facility for adding the trailing NewLine Assert.AreEqual(dotNetStack.ToString(), stack.ToString(StackFormat.TrailingNewLine)); }
public bool ValueEquals(Stack other) => ValueComparer.Equals(this, other);