Microsoft.CodeAnalysis.Sarif.Errors.LogTargetParseError C# (CSharp) Method

LogTargetParseError() public static method

public static LogTargetParseError ( IAnalysisContext context, Region region, string message ) : void
context IAnalysisContext
region Region
message string
return void
        public static void LogTargetParseError(IAnalysisContext context, Region region, string message)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // {0}({1}): error {2}: {3}
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR1000_ParseError,
                    NotificationLevel.Error,
                    null,
                    false,
                    context.TargetUri.LocalPath,
                    region.FormatForVisualStudio(),
                    ERR1000_ParseError,
                    message));

            context.RuntimeErrors |= RuntimeConditions.TargetParseError;
        }

Usage Example

Esempio n. 1
0
        public override void Analyze(TestAnalysisContext context)
        {
            TestRuleBehaviors testRuleBehaviors = context.Policy.GetProperty(Behaviors);

            // Currently, we only allow test rule behavior either be passed by context
            // or injected via static data, not by both mechanisms.
            (s_testRuleBehaviors == 0 || testRuleBehaviors == 0).Should().BeTrue();

            if (testRuleBehaviors == TestRuleBehaviors.None)
            {
                testRuleBehaviors = s_testRuleBehaviors;
            }
            ;

            switch (testRuleBehaviors)
            {
            case TestRuleBehaviors.RaiseExceptionInvokingAnalyze:
            {
                throw new InvalidOperationException(nameof(TestRuleBehaviors.RaiseExceptionInvokingAnalyze));
            }

            case TestRuleBehaviors.RaiseTargetParseError:
            {
                Errors.LogTargetParseError(
                    context,
                    new Region
                    {
                        StartLine   = 42,
                        StartColumn = 54
                    },
                    "Could not parse target.");
                break;
            }

            case TestRuleBehaviors.LogError:
            {
                context.Logger.Log(this,
                                   new Result
                    {
                        RuleId  = this.Id,
                        Level   = FailureLevel.Error,
                        Message = new Message {
                            Text = "Simple test rule message."
                        }
                    });
                break;
            }

            default:
            {
                break;
            }
            }

            string fileName = Path.GetFileName(context.TargetUri.LocalPath);

            if (fileName.Contains(nameof(FailureLevel.Error)))
            {
                context.Logger.Log(this,
                                   RuleUtilities.BuildResult(FailureLevel.Error, context, null,
                                                             nameof(SkimmerBaseTestResources.TEST1001_Failed),
                                                             context.TargetUri.GetFileName()));
            }
            if (fileName.Contains(nameof(FailureLevel.Warning)))
            {
                context.Logger.Log(this,
                                   RuleUtilities.BuildResult(FailureLevel.Warning, context, null,
                                                             nameof(SkimmerBaseTestResources.TEST1001_Failed),
                                                             context.TargetUri.GetFileName()));
            }
            if (fileName.Contains(nameof(FailureLevel.Note)))
            {
                context.Logger.Log(this,
                                   RuleUtilities.BuildResult(FailureLevel.Note, context, null,
                                                             nameof(SkimmerBaseTestResources.TEST1001_Note),
                                                             context.TargetUri.GetFileName()));
            }
            else if (fileName.Contains(nameof(ResultKind.Pass)))
            {
                context.Logger.Log(this,
                                   RuleUtilities.BuildResult(ResultKind.Pass, context, null,
                                                             nameof(SkimmerBaseTestResources.TEST1001_Pass),
                                                             context.TargetUri.GetFileName()));
            }
            else if (fileName.Contains(nameof(ResultKind.Review)))
            {
                context.Logger.Log(this,
                                   RuleUtilities.BuildResult(ResultKind.Review, context, null,
                                                             nameof(SkimmerBaseTestResources.TEST1001_Review),
                                                             context.TargetUri.GetFileName()));
            }
            else if (fileName.Contains(nameof(ResultKind.Open)))
            {
                context.Logger.Log(this,
                                   RuleUtilities.BuildResult(ResultKind.Open, context, null,
                                                             nameof(SkimmerBaseTestResources.TEST1001_Open),
                                                             context.TargetUri.GetFileName()));
            }
            else if (fileName.Contains(nameof(ResultKind.Informational)))
            {
                context.Logger.Log(this,
                                   RuleUtilities.BuildResult(ResultKind.Informational, context, null,
                                                             nameof(SkimmerBaseTestResources.TEST1001_Information),
                                                             context.TargetUri.GetFileName()));
            }
        }
All Usage Examples Of Microsoft.CodeAnalysis.Sarif.Errors::LogTargetParseError