Microsoft.CodeAnalysis.Sarif.RuleUtilities.BuildResult C# (CSharp) Method

BuildResult() public static method

public static BuildResult ( ResultLevel level, IAnalysisContext context, Region region, string formatId ) : Result
level ResultLevel
context IAnalysisContext
region Region
formatId string
return Result
        public static Result BuildResult(ResultLevel level, IAnalysisContext context, Region region, string formatId, params string[] arguments)
        {
            //validating parameters
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (arguments == null)
            {
                throw new ArgumentNullException(nameof(arguments));
            }

            formatId = RuleUtilities.NormalizeFormatId(context.Rule.Id, formatId);

            Result result = new Result
            {
                RuleId = context.Rule.Id,

                FormattedRuleMessage = new FormattedRuleMessage()
                {
                    FormatId = formatId,
                    Arguments = arguments
                },

                Level = level
            };

            string targetPath = context.TargetUri?.LocalPath;
            if (targetPath != null)
            {
                result.Locations = new List<Location> {
                    new Sarif.Location {
                        AnalysisTarget = new PhysicalLocation
                        {
                            Uri = new Uri(targetPath),
                            Region = region
                        }
               }};
            }
            return result;
        }

Usage Example

Esempio n. 1
0
        public static void LogNotApplicableToSpecifiedTarget(IAnalysisContext context, string reasonForNotAnalyzing)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            Debug.Assert(context.TargetUri != null);

            // '{0}' was not evaluated for check '{1}' because the analysis
            // is not relevant for the following reason: {2}.
            context.Logger.Log(context.Rule,
                               RuleUtilities.BuildResult(ResultKind.NotApplicable, context, null,
                                                         nameof(SdkResources.NotApplicable_InvalidMetadata),
                                                         context.TargetUri.GetFileName(),
                                                         context.Rule.Name,
                                                         reasonForNotAnalyzing));

            context.RuntimeErrors |= RuntimeConditions.RuleNotApplicableToTarget;
        }
All Usage Examples Of Microsoft.CodeAnalysis.Sarif.RuleUtilities::BuildResult