Microsoft.CodeAnalysis.Sarif.Converters.CppCheckError.ToSarifIssue C# (CSharp) Method

ToSarifIssue() public method

Converts this instance to Result.
public ToSarifIssue ( ) : System.Result
return System.Result
        public Result ToSarifIssue()
        {
            if (this.Locations.Length == 0)
            {
                throw new InvalidOperationException("At least one location must be present in a SARIF result.");
            }

            var result = new Result
            {
                RuleId = this.Id,
            };

            result.SetProperty("Severity", this.Severity);

            if (!string.IsNullOrEmpty(this.VerboseMessage))
            {
                result.Message = this.VerboseMessage;
            }
            else
            {
                result.Message = this.Message;
            }

            PhysicalLocation lastLocationConverted;
            if (this.Locations.Length == 1)
            {
                lastLocationConverted = this.Locations[0].ToSarifPhysicalLocation();
            }
            else
            {
                var locations = new List<AnnotatedCodeLocation>
                {
                    Capacity = this.Locations.Length
                };

                foreach (CppCheckLocation loc in this.Locations)
                {
                    locations.Add(new AnnotatedCodeLocation
                    {
                        PhysicalLocation = loc.ToSarifPhysicalLocation(),
                        Importance = AnnotatedCodeLocationImportance.Essential
                    });
                }

                var flow = new CodeFlow
                {
                    Locations = locations
                };

                result.CodeFlows = new List<CodeFlow> { flow };

                // In the N != 1 case, set the overall location's location to
                // the last entry in the execution flow.
                lastLocationConverted = locations[locations.Count - 1].PhysicalLocation;
            }

            result.Locations = new List<Location>
            {
                new Location
                {
                    ResultFile = lastLocationConverted
                }
            };

            return result;
        }