/// <summary> /// Converts an exception stack to a sarif code location list. /// </summary> public static IList<AnnotatedCodeLocation> ToCodeLocations(this Exception exception) { List<AnnotatedCodeLocation> codeLocations = new List<AnnotatedCodeLocation>(); StackTrace stack = new StackTrace(exception); foreach (StackFrame frame in stack.GetFrames()) { AnnotatedCodeLocation codeLocation = new AnnotatedCodeLocation(); MemberInfo member = frame.GetMethod(); if (member != null) { codeLocation.Message = member.ReflectedType.FullName + "." + member.Name; } PhysicalLocationComponent physicalLocation = new PhysicalLocationComponent(); string filename = frame.GetFileName(); if (!String.IsNullOrWhiteSpace(filename)) { physicalLocation.Uri = new Uri(filename); } physicalLocation.Region = new Region(); physicalLocation.Region.StartLine = frame.GetFileLineNumber(); physicalLocation.Region.EndLine = frame.GetFileLineNumber(); physicalLocation.Region.StartColumn = frame.GetFileColumnNumber(); physicalLocation.Region.EndColumn = frame.GetFileColumnNumber(); codeLocation.PhysicalLocation = new List<PhysicalLocationComponent>() { physicalLocation }; codeLocations.Add(codeLocation); } return codeLocations; }
public virtual AnnotatedCodeLocation VisitAnnotatedCodeLocation(AnnotatedCodeLocation node) { if (node != null) { node.PhysicalLocation = VisitNullChecked(node.PhysicalLocation); } return(node); }
/// <summary> /// Initializes a new instance of the <see cref="AnnotatedCodeLocation" /> 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 AnnotatedCodeLocation(AnnotatedCodeLocation other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } Init(other.Id, other.Step, other.PhysicalLocation, other.FullyQualifiedLogicalName, other.LogicalLocationKey, other.Module, other.ThreadId, other.Message, other.Kind, other.TaintKind, other.Target, other.Values, other.State, other.TargetKey, other.Essential, other.Importance, other.Snippet, other.Annotations, other.Properties); }
public virtual AnnotatedCodeLocation VisitAnnotatedCodeLocation(AnnotatedCodeLocation node) { if (node != null) { node.PhysicalLocation = VisitNullChecked(node.PhysicalLocation); if (node.Annotations != null) { for (int index_0 = 0; index_0 < node.Annotations.Count; ++index_0) { node.Annotations[index_0] = VisitNullChecked(node.Annotations[index_0]); } } } return(node); }
public bool ValueEquals(AnnotatedCodeLocation other) => ValueComparer.Equals(this, other);