private static string[] GetExpectedArguments(string parameterName, StartActionKind kind)
        {
            string endActionName;
            string statelessActionName;
            string arg4;

            switch (kind)
            {
            case StartActionKind.CompilationStartAction:
                endActionName       = "CompilationEndAction";
                statelessActionName = "RegisterCompilationAction";
                arg4 = "Initialize";
                break;

            case StartActionKind.CodeBlockStartAction:
                endActionName       = "CodeBlockEndAction";
                statelessActionName = "RegisterCodeBlockAction";
                arg4 = "Initialize, CompilationStartAction";
                break;

            case StartActionKind.OperationBlockStartAction:
                endActionName       = "OperationBlockEndAction";
                statelessActionName = "RegisterOperationBlockAction";
                arg4 = "Initialize, CompilationStartAction";
                break;

            default:
                throw new ArgumentException("Unsupported argument kind", nameof(kind));
            }

            return(new[] { parameterName, endActionName, statelessActionName, arg4 });
        }
Пример #2
0
        private static string[] GetExpectedArguments(string parameterName, StartActionKind kind)
        {
            var arg2 = kind switch
            {
                StartActionKind.CompilationStartAction => "Initialize",
                StartActionKind.CodeBlockStartAction
                or StartActionKind.OperationBlockStartAction => "Initialize, CompilationStartAction",
                _ => throw new ArgumentException("Unsupported action kind", nameof(kind)),
            };

            return(new[] { parameterName, arg2 });
        }
        private static string[] GetExpectedArguments(string parameterName, StartActionKind kind)
        {
            string arg2;

            switch (kind)
            {
            case StartActionKind.CompilationStartAction:
                arg2 = "Initialize";
                break;

            case StartActionKind.CodeBlockStartAction:
            case StartActionKind.OperationBlockStartAction:
                arg2 = "Initialize, CompilationStartAction";
                break;

            default:
                throw new ArgumentException("Unsupported action kind", nameof(kind));
            }

            return(new[] { parameterName, arg2 });
        }
        private static DiagnosticResult GetExpectedDiagnostic(string language, int line, int column, string parameterName, StartActionKind kind)
        {
            string arg2;            
            switch (kind)
            {
                case StartActionKind.CompilationStartAction:
                    arg2 = "Initialize";
                    break;

                case StartActionKind.CodeBlockStartAction:
                case StartActionKind.OperationBlockStartAction:
                    arg2 = "Initialize, CompilationStartAction";
                    break;

                default:
                    throw new ArgumentException("Unsupported action kind", "kind");
            }

            string message = string.Format(CodeAnalysisDiagnosticsResources.StartActionWithNoRegisteredActionsMessage, parameterName, arg2);

            string fileName = language == LanguageNames.CSharp ? "Test0.cs" : "Test0.vb";
            return new DiagnosticResult
            {
                Id = DiagnosticIds.StartActionWithNoRegisteredActionsRuleId,
                Message = message,
                Severity = DiagnosticSeverity.Warning,
                Locations = new[]
                {
                    new DiagnosticResultLocation(fileName, line, column)
                }
            };
        }
        private static DiagnosticResult GetExpectedDiagnostic(int line, int column, string parameterName, StartActionKind kind)
        {
            string endActionName;
            string statelessActionName;
            string arg4;

            switch (kind)
            {
            case StartActionKind.CompilationStartAction:
                endActionName       = "CompilationEndAction";
                statelessActionName = "RegisterCompilationAction";
                arg4 = "Initialize";
                break;

            case StartActionKind.CodeBlockStartAction:
                endActionName       = "CodeBlockEndAction";
                statelessActionName = "RegisterCodeBlockAction";
                arg4 = "Initialize, CompilationStartAction";
                break;

            case StartActionKind.OperationBlockStartAction:
                endActionName       = "OperationBlockEndAction";
                statelessActionName = "RegisterOperationBlockAction";
                arg4 = "Initialize, CompilationStartAction";
                break;

            default:
                throw new ArgumentException("Unsupported argument kind", nameof(kind));
            }

            string message = string.Format(CodeAnalysisDiagnosticsResources.StartActionWithOnlyEndActionMessage, parameterName, endActionName, statelessActionName, arg4);

            return(new DiagnosticResult(DiagnosticIds.StartActionWithOnlyEndActionRuleId, DiagnosticHelpers.DefaultDiagnosticSeverity)
                   .WithLocation(line, column)
                   .WithMessageFormat(message));
        }
        private static DiagnosticResult GetBasicExpectedDiagnostic(int line, int column, string parameterName, StartActionKind kind) =>
#pragma warning disable RS0030 // Do not used banned APIs
        VerifyVB.Diagnostic(BasicRegisterActionAnalyzer.StartActionWithOnlyEndActionRule)
        .WithLocation(line, column)
#pragma warning restore RS0030 // Do not used banned APIs
        .WithArguments(GetExpectedArguments(parameterName, kind));
        private static DiagnosticResult GetExpectedDiagnostic(string language, int line, int column, string parameterName, StartActionKind kind)
        {
            string endActionName;
            string statelessActionName;
            string arg4;
            switch (kind)
            {
                case StartActionKind.CompilationStartAction:
                    endActionName = "CompilationEndAction";
                    statelessActionName = "RegisterCompilationAction";
                    arg4 = "Initialize";
                    break;

                case StartActionKind.CodeBlockStartAction:
                    endActionName = "CodeBlockEndAction";
                    statelessActionName = "RegisterCodeBlockAction";
                    arg4 = "Initialize, CompilationStartAction";
                    break;

                case StartActionKind.OperationBlockStartAction:
                    endActionName = "OperationBlockEndAction";
                    statelessActionName = "RegisterOperationBlockAction";
                    arg4 = "Initialize, CompilationStartAction";
                    break;

                default:
                    throw new ArgumentException("kind");
            }

            string message = string.Format(CodeAnalysisDiagnosticsResources.StartActionWithOnlyEndActionMessage, parameterName, endActionName, statelessActionName, arg4);

            string fileName = language == LanguageNames.CSharp ? "Test0.cs" : "Test0.vb";
            return new DiagnosticResult
            {
                Id = DiagnosticIds.StartActionWithOnlyEndActionRuleId,
                Message = message,
                Severity = DiagnosticSeverity.Warning,
                Locations = new[]
                {
                    new DiagnosticResultLocation(fileName, line, column)
                }
            };
        }
 private static DiagnosticResult GetCSharpExpectedDiagnostic(int line, int column, string parameterName, StartActionKind kind)
 {
     return(GetExpectedDiagnostic(line, column, parameterName, kind));
 }
Пример #9
0
        private static DiagnosticResult GetExpectedDiagnostic(string language, int line, int column, string parameterName, StartActionKind kind)
        {
            string endActionName;
            string statelessActionName;
            string arg4;

            switch (kind)
            {
            case StartActionKind.CompilationStartAction:
                endActionName       = "CompilationEndAction";
                statelessActionName = "RegisterCompilationAction";
                arg4 = "Initialize";
                break;

            case StartActionKind.CodeBlockStartAction:
                endActionName       = "CodeBlockEndAction";
                statelessActionName = "RegisterCodeBlockAction";
                arg4 = "Initialize, CompilationStartAction";
                break;

            case StartActionKind.OperationBlockStartAction:
                endActionName       = "OperationBlockEndAction";
                statelessActionName = "RegisterOperationBlockAction";
                arg4 = "Initialize, CompilationStartAction";
                break;

            default:
                throw new ArgumentException("Unsupported argument kind", nameof(kind));
            }

            string message = string.Format(CodeAnalysisDiagnosticsResources.StartActionWithOnlyEndActionMessage, parameterName, endActionName, statelessActionName, arg4);

            string fileName = language == LanguageNames.CSharp ? "Test0.cs" : "Test0.vb";

            return(new DiagnosticResult
            {
                Id = DiagnosticIds.StartActionWithOnlyEndActionRuleId,
                Message = message,
                Severity = DiagnosticHelpers.DefaultDiagnosticSeverity,
                Locations = new[]
                {
                    new DiagnosticResultLocation(fileName, line, column)
                }
            });
        }
 private static DiagnosticResult GetBasicExpectedDiagnostic(int line, int column, string parameterName, StartActionKind kind)
 {
     return GetExpectedDiagnostic(LanguageNames.VisualBasic, line, column, parameterName, kind);
 }
Пример #11
0
 private static DiagnosticResult GetBasicExpectedDiagnostic(int line, int column, string parameterName, StartActionKind kind)
 {
     return(GetExpectedDiagnostic(LanguageNames.VisualBasic, line, column, parameterName, kind));
 }
Пример #12
0
        private static DiagnosticResult GetExpectedDiagnostic(DiagnosticDescriptor rule, int line, int column, string parameterName, StartActionKind kind)
        {
            string endActionName;
            string statelessActionName;
            string arg4;

            switch (kind)
            {
            case StartActionKind.CompilationStartAction:
                endActionName       = "CompilationEndAction";
                statelessActionName = "RegisterCompilationAction";
                arg4 = "Initialize";
                break;

            case StartActionKind.CodeBlockStartAction:
                endActionName       = "CodeBlockEndAction";
                statelessActionName = "RegisterCodeBlockAction";
                arg4 = "Initialize, CompilationStartAction";
                break;

            case StartActionKind.OperationBlockStartAction:
                endActionName       = "OperationBlockEndAction";
                statelessActionName = "RegisterOperationBlockAction";
                arg4 = "Initialize, CompilationStartAction";
                break;

            default:
                throw new ArgumentException("Unsupported argument kind", nameof(kind));
            }

            return(new DiagnosticResult(rule)
                   .WithLocation(line, column)
                   .WithArguments(parameterName, endActionName, statelessActionName, arg4));
        }
 private static DiagnosticResult GetBasicExpectedDiagnostic(int line, int column, string parameterName, StartActionKind kind) =>
 VerifyVB.Diagnostic(BasicRegisterActionAnalyzer.StartActionWithNoRegisteredActionsRule)
 .WithLocation(line, column)
 .WithArguments(GetExpectedArguments(parameterName, kind));
 private static DiagnosticResult GetCSharpExpectedDiagnostic(int line, int column, string parameterName, StartActionKind kind) =>
 VerifyCS.Diagnostic(CSharpRegisterActionAnalyzer.StartActionWithOnlyEndActionRule)
 .WithLocation(line, column)
 .WithArguments(GetExpectedArguments(parameterName, kind));
Пример #15
0
 private static DiagnosticResult GetBasicExpectedDiagnostic(int line, int column, string parameterName, StartActionKind kind)
 {
     return(GetExpectedDiagnostic(VisualBasic.Analyzers.MetaAnalyzers.BasicRegisterActionAnalyzer.StartActionWithNoRegisteredActionsRule,
                                  line, column, parameterName, kind));
 }
        private static DiagnosticResult GetExpectedDiagnostic(string language, int line, int column, string parameterName, StartActionKind kind)
        {
            string arg2;

            switch (kind)
            {
            case StartActionKind.CompilationStartAction:
                arg2 = "Initialize";
                break;

            case StartActionKind.CodeBlockStartAction:
            case StartActionKind.OperationBlockStartAction:
                arg2 = "Initialize, CompilationStartAction";
                break;

            default:
                throw new ArgumentException("Unsupported action kind", nameof(kind));
            }

            string message = string.Format(CultureInfo.CurrentCulture, CodeAnalysisDiagnosticsResources.StartActionWithNoRegisteredActionsMessage, parameterName, arg2);

            string fileName = language == LanguageNames.CSharp ? "Test0.cs" : "Test0.vb";

            return(new DiagnosticResult(DiagnosticIds.StartActionWithNoRegisteredActionsRuleId, DiagnosticHelpers.DefaultDiagnosticSeverity)
                   .WithLocation(fileName, line, column)
                   .WithMessageFormat(message));
        }
Пример #17
0
        private static DiagnosticResult GetExpectedDiagnostic(DiagnosticDescriptor rule, int line, int column, string parameterName, StartActionKind kind)
        {
            string arg2;

            switch (kind)
            {
            case StartActionKind.CompilationStartAction:
                arg2 = "Initialize";
                break;

            case StartActionKind.CodeBlockStartAction:
            case StartActionKind.OperationBlockStartAction:
                arg2 = "Initialize, CompilationStartAction";
                break;

            default:
                throw new ArgumentException("Unsupported action kind", nameof(kind));
            }

            return(new DiagnosticResult(rule)
                   .WithLocation(line, column)
                   .WithArguments(parameterName, arg2));
        }
Пример #18
0
        private static DiagnosticResult GetExpectedDiagnostic(string language, int line, int column, string parameterName, StartActionKind kind)
        {
            string arg2;

            switch (kind)
            {
            case StartActionKind.CompilationStartAction:
                arg2 = "Initialize";
                break;

            case StartActionKind.CodeBlockStartAction:
            case StartActionKind.OperationBlockStartAction:
                arg2 = "Initialize, CompilationStartAction";
                break;

            default:
                throw new ArgumentException("Unsupported action kind", "kind");
            }

            string message = string.Format(CodeAnalysisDiagnosticsResources.StartActionWithNoRegisteredActionsMessage, parameterName, arg2);

            string fileName = language == LanguageNames.CSharp ? "Test0.cs" : "Test0.vb";

            return(new DiagnosticResult
            {
                Id = DiagnosticIds.StartActionWithNoRegisteredActionsRuleId,
                Message = message,
                Severity = DiagnosticSeverity.Warning,
                Locations = new[]
                {
                    new DiagnosticResultLocation(fileName, line, column)
                }
            });
        }
Пример #19
0
 private static DiagnosticResult GetCSharpExpectedDiagnostic(int line, int column, string parameterName, StartActionKind kind)
 {
     return(GetExpectedDiagnostic(CSharp.Analyzers.MetaAnalyzers.CSharpRegisterActionAnalyzer.StartActionWithOnlyEndActionRule,
                                  line, column, parameterName, kind));
 }