Inheritance: PropertyBagHolder, ISarifNode
        /// <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);
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 public bool ValueEquals(AnnotatedCodeLocation other) => ValueComparer.Equals(this, other);
Exemplo n.º 6
0
        /// <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);
        }
Exemplo n.º 7
0
 public bool ValueEquals(AnnotatedCodeLocation other) => ValueComparer.Equals(this, other);