Microsoft.CodeAnalysis.Sarif.Converters.FxCopConverter.CreateResult C# (CSharp) Method

CreateResult() private method

private CreateResult ( FxCopLogReader context ) : System.Result
context FxCopLogReader
return System.Result
        internal Result CreateResult(FxCopLogReader.Context context)
        {
            Result result = new Result();

            string uniqueId = context.GetUniqueId();
            if (!String.IsNullOrWhiteSpace(uniqueId))
            {
                result.ToolFingerprintContribution = uniqueId;
            }

            string status = context.Status;

            if ("ExcludedInSource".Equals(status))
            {
                result.SuppressionStates = SuppressionStates.SuppressedInSource;
            }
            else if ("ExcludedInProject".Equals(status))
            {
                result.BaselineState = BaselineState.Existing;
            }

            result.RuleId = context.CheckId;
            result.Message = context.Message;
            var location = new Location();

            if (!String.IsNullOrEmpty(context.Target))
            {
                location.AnalysisTarget = new PhysicalLocation
                {
                    Uri = new Uri(context.Target, UriKind.RelativeOrAbsolute)
                };

            }

            string sourceFile = GetFilePath(context);
            if (!String.IsNullOrWhiteSpace(sourceFile))
            {
                location.ResultFile = new PhysicalLocation
                {
                    Uri = new Uri(sourceFile, UriKind.RelativeOrAbsolute),
                    Region = context.Line == null ? null : Extensions.CreateRegion(context.Line.Value)
                };
            }

            location.FullyQualifiedLogicalName = CreateSignature(context);

            string logicalLocationKey = CreateLogicalLocation(context);

            if (logicalLocationKey != location.FullyQualifiedLogicalName)
            {
                location.LogicalLocationKey = logicalLocationKey;
            }

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

            bool mapsDirectlyToSarifName;

            result.Level = ConvertFxCopLevelToResultLevel(context.Level, out mapsDirectlyToSarifName);

            if (!mapsDirectlyToSarifName)
            {
                // We will not recapitulate FxCop MessageLevel names (such as
                // "Error" and "Warning") as a property. For names that differ
                // (such as "CriticalWarning" and "Information"), we will also
                // include the FxCop-specific values in the property bag.
                TryAddProperty(result, context.Level, "Level");
            }

            TryAddProperty(result, context.Category, "Category");
            TryAddProperty(result, context.FixCategory, "FixCategory");

            return result;
        }

Usage Example

Exemplo n.º 1
0
        public void FxCopConverter_CreateResult_FakeContext_Resource()
        {
            var context = TestHelper.CreateProjectContext();

            context.RefineTarget(@"mybinary.dll");
            context.RefineModule("mybinary.dll");
            context.RefineResource("myresource.resx");
            context.RefineMessage("CA0000", "VeryUsefulCheck", null, null, null, null);
            context.RefineIssue("hello!", "test", null, null, @"source", "myfile.cs", 13);

            var expectedLogicalLocations = new List <LogicalLocation>
            {
                new LogicalLocation {
                    Kind = LogicalLocationKind.Module, Name = "mybinary.dll"
                },
                new LogicalLocation {
                    ParentIndex = 0, Name = "myresource.resx", FullyQualifiedName = "mybinary.dll!myresource.resx", Kind = LogicalLocationKind.Resource
                }
            };

            var    converter = new FxCopConverter();
            Result result    = converter.CreateResult(context);

            ValidateLogicalLocations(expectedLogicalLocations, converter.LogicalLocations);
        }
All Usage Examples Of Microsoft.CodeAnalysis.Sarif.Converters.FxCopConverter::CreateResult