• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Diagnostics.AnalyzerOptions类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.CodeAnalysis.Diagnostics.AnalyzerOptions的典型用法代码示例。如果您正苦于以下问题:C# AnalyzerOptions类的具体用法?C# AnalyzerOptions怎么用?C# AnalyzerOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AnalyzerOptions类属于Microsoft.CodeAnalysis.Diagnostics命名空间,在下文中一共展示了AnalyzerOptions类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: AnalyzerDriver

        /// <summary>
        /// Create an analyzer driver.
        /// </summary>
        /// <param name="analyzers">The set of analyzers to include in the analysis</param>
        /// <param name="options">Options that are passed to analyzers</param>
        /// <param name="cancellationToken">a cancellation token that can be used to abort analysis</param>
        /// <param name="continueOnAnalyzerException">Delegate which is invoked when an analyzer throws an exception.
        /// If a non-null delegate is provided and it returns true, then the exception is handled and converted into a diagnostic and driver continues with other analyzers.
        /// Otherwise if it returns false, then the exception is not handled by the driver.
        /// If null, then the driver always handles the exception.
        /// </param>
        protected AnalyzerDriver(ImmutableArray<IDiagnosticAnalyzer> analyzers, AnalyzerOptions options, CancellationToken cancellationToken, Func<Exception, IDiagnosticAnalyzer, bool> continueOnAnalyzerException = null)
        {
            this.CompilationEventQueue = new AsyncQueue<CompilationEvent>();
            this.DiagnosticQueue = new AsyncQueue<Diagnostic>();
            this.addDiagnostic = GetDiagnosticSinkWithSuppression();
            this.analyzerOptions = options;

            Func<Exception, IDiagnosticAnalyzer, bool> defaultExceptionHandler = (exception, analyzer) => true;
            this.continueOnAnalyzerException = continueOnAnalyzerException ?? defaultExceptionHandler;

            // start the first task to drain the event queue. The first compilation event is to be handled before
            // any other ones, so we cannot have more than one event processing task until the first event has been handled.
            initialWorker = Task.Run(async () =>
            {
                try
                {
                    await InitialWorkerAsync(analyzers, continueOnAnalyzerException, cancellationToken).ConfigureAwait(false);
                }
                catch (OperationCanceledException)
                {
                    // If creation is cancelled we had better not use the driver any longer
                    this.Dispose();
                }
            });
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:36,代码来源:AnalyzerDriver.cs


示例2: AnalyzeSymbol

 protected override void AnalyzeSymbol(INamedTypeSymbol namedTypeSymbol, Compilation compilation, Action<Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
 {
     if (namedTypeSymbol.IsValueType && IsOverridesEquals(namedTypeSymbol) && !IsEqualityOperatorImplemented(namedTypeSymbol))
     {
         addDiagnostic(namedTypeSymbol.CreateDiagnostic(Rule));
     }
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:7,代码来源:CA2231DiagnosticAnalyzer.cs


示例3: CompilationWithAnalyzersOptions

 /// <summary>
 /// Creates a new <see cref="CompilationWithAnalyzersOptions"/>.
 /// </summary>
 /// <param name="options">Options that are passed to analyzers.</param>
 /// <param name="onAnalyzerException">Action to invoke if an analyzer throws an exception.</param>
 /// <param name="concurrentAnalysis">Flag indicating whether analysis can be performed concurrently on multiple threads.</param>
 /// <param name="logAnalyzerExecutionTime">Flag indicating whether analyzer execution time should be logged.</param>
 public CompilationWithAnalyzersOptions(AnalyzerOptions options, Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException, bool concurrentAnalysis, bool logAnalyzerExecutionTime)
 {
     _options = options;
     _onAnalyzerException = onAnalyzerException;
     _concurrentAnalysis = concurrentAnalysis;
     _logAnalyzerExecutionTime = logAnalyzerExecutionTime;
 }
开发者ID:noahstein,项目名称:roslyn,代码行数:14,代码来源:CompilationWithAnalyzersOptions.cs


示例4: CreateAnalyzerWithinCompilation

        public IDiagnosticAnalyzer CreateAnalyzerWithinCompilation(Compilation compilation, AnalyzerOptions options, CancellationToken cancellationToken)
        {
            var iserializableTypeSymbol = compilation.GetTypeByMetadataName("System.Runtime.Serialization.ISerializable");
            if (iserializableTypeSymbol == null)
            {
                return null;
            }

            var serializationInfoTypeSymbol = compilation.GetTypeByMetadataName("System.Runtime.Serialization.SerializationInfo");
            if (serializationInfoTypeSymbol == null)
            {
                return null;
            }

            var streamingContextTypeSymbol = compilation.GetTypeByMetadataName("System.Runtime.Serialization.StreamingContext");
            if (streamingContextTypeSymbol == null)
            {
                return null;
            }

            var serializableAttributeTypeSymbol = compilation.GetTypeByMetadataName("System.SerializableAttribute");
            if (serializableAttributeTypeSymbol == null)
            {
                return null;
            }

            return new Analyzer(iserializableTypeSymbol, serializationInfoTypeSymbol, streamingContextTypeSymbol, serializableAttributeTypeSymbol);
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:28,代码来源:SerializationRulesDiagnosticAnalyzer.cs


示例5: OnCodeBlockStarted

        public ICodeBlockEndedAnalyzer OnCodeBlockStarted(SyntaxNode codeBlock, ISymbol ownerSymbol, SemanticModel semanticModel, Action<Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
        {
            var methodSymbol = ownerSymbol as IMethodSymbol;

            if (methodSymbol == null ||
                methodSymbol.ReturnsVoid ||
                methodSymbol.ReturnType.Kind == SymbolKind.ArrayType ||
                methodSymbol.Parameters.Length > 0 ||
                !(methodSymbol.DeclaredAccessibility == Accessibility.Public || methodSymbol.DeclaredAccessibility == Accessibility.Protected) ||
                methodSymbol.IsAccessorMethod() ||
                !IsPropertyLikeName(methodSymbol.Name))
            {
                return null;
            }

            // Fxcop has a few additional checks to reduce the noise for this diagnostic:
            // Ensure that the method is non-generic, non-virtual/override, has no overloads and doesn't have special names: 'GetHashCode' or 'GetEnumerator'.
            // Also avoid generating this diagnostic if the method body has any invocation expressions.
            if (methodSymbol.IsGenericMethod ||
                methodSymbol.IsVirtual ||
                methodSymbol.IsOverride ||
                methodSymbol.ContainingType.GetMembers(methodSymbol.Name).Length > 1 ||
                methodSymbol.Name == GetHashCodeName ||
                methodSymbol.Name == GetEnumeratorName)
            {
                return null;
            }

            return GetCodeBlockEndedAnalyzer();
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:30,代码来源:CA1024DiagnosticAnalyzer.cs


示例6: AnalyzeSymbol

        public override void AnalyzeSymbol(INamedTypeSymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
        {
            if (symbol.TypeKind != TypeKind.Enum)
            {
                return;
            }

            var flagsAttribute = WellKnownTypes.FlagsAttribute(compilation);
            if (flagsAttribute == null)
            {
                return;
            }

            var zeroValuedFields = GetZeroValuedFields(symbol).ToImmutableArray();

            bool hasFlagsAttribute = symbol.GetAttributes().Any(a => a.AttributeClass == flagsAttribute);
            if (hasFlagsAttribute)
            {
                CheckFlags(symbol, zeroValuedFields, addDiagnostic);
            }
            else
            {
                CheckNonFlags(symbol, zeroValuedFields, addDiagnostic);
            }
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:25,代码来源:CA1008DiagnosticAnalyzer.cs


示例7: AnalyzeSymbol

 public override void AnalyzeSymbol(INamedTypeSymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
 {
     if (symbol.GetMembers().Any(member => IsDllImport(member)) && !IsTypeNamedCorrectly(symbol.Name))
     {
         addDiagnostic(symbol.CreateDiagnostic(Rule));
     }
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:7,代码来源:CA1060DiagnosticAnalyzer.cs


示例8: OnCompilationStarted

        public ICompilationEndedAnalyzer OnCompilationStarted(Compilation compilation, Action<Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
        {
            var eventHandler = WellKnownTypes.EventHandler(compilation);
            if (eventHandler == null)
            {
                return null;
            }

            var genericEventHandler = WellKnownTypes.GenericEventHandler(compilation);
            if (genericEventHandler == null)
            {
                return null;
            }

            var eventArgs = WellKnownTypes.EventArgs(compilation);
            if (eventArgs == null)
            {
                return null;
            }

            var comSourceInterfacesAttribute = WellKnownTypes.ComSourceInterfaceAttribute(compilation);
            if (comSourceInterfacesAttribute == null)
            {
                return null;
            }

            return GetAnalyzer(compilation, eventHandler, genericEventHandler, eventArgs, comSourceInterfacesAttribute);
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:28,代码来源:CA1003DiagnosticAnalyzer.cs


示例9: AnalyzeCompilation

        public void AnalyzeCompilation(Compilation compilation, Action<Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
        {
            if (AssemblyHasPublicTypes(compilation.Assembly))
            {
                var comVisibleAttributeSymbol = WellKnownTypes.ComVisibleAttribute(compilation);
                if (comVisibleAttributeSymbol == null)
                {
                    return;
                }

                var attributeInstance = compilation.Assembly.GetAttributes().FirstOrDefault(a => a.AttributeClass.Equals(comVisibleAttributeSymbol));

                if (attributeInstance != null)
                {
                    if (attributeInstance.ConstructorArguments.Length > 0 &&
                        attributeInstance.ConstructorArguments[0].Kind == TypedConstantKind.Primitive &&
                        attributeInstance.ConstructorArguments[0].Value != null &
                        attributeInstance.ConstructorArguments[0].Value.Equals(true))
                    {
                        // Has the attribute, with the value 'true'.
                        addDiagnostic(Diagnostic.Create(Rule, Location.None, string.Format(FxCopRulesResources.CA1017_AttributeTrue, compilation.Assembly.Name)));
                    }
                }
                else
                {
                    // No ComVisible attribute at all.
                    addDiagnostic(Diagnostic.Create(Rule, Location.None, string.Format(FxCopRulesResources.CA1017_NoAttribute, compilation.Assembly.Name)));
                }
            }

            return;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:32,代码来源:CA1017DiagnosticAnalyzer.cs


示例10: CreateAnalyzerWithinCompilation

        public IDiagnosticAnalyzer CreateAnalyzerWithinCompilation(Compilation compilation, AnalyzerOptions options, CancellationToken cancellationToken)
        {
            var dllImportType = compilation.GetTypeByMetadataName("System.Runtime.InteropServices.DllImportAttribute");
            if (dllImportType == null)
            {
                return null;
            }

            var marshalAsType = compilation.GetTypeByMetadataName("System.Runtime.InteropServices.MarshalAsAttribute");
            if (marshalAsType == null)
            {
                return null;
            }

            var stringBuilderType = compilation.GetTypeByMetadataName("System.Text.StringBuilder");
            if (stringBuilderType == null)
            {
                return null;
            }

            var unmanagedType = compilation.GetTypeByMetadataName("System.Runtime.InteropServices.UnmanagedType");
            if (unmanagedType == null)
            {
                return null;
            }

            return new Analyzer(dllImportType, marshalAsType, stringBuilderType, unmanagedType);
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:28,代码来源:PInvokeDiagnosticAnalyzer.cs


示例11: CreateAnalyzerWithinCompilation

        public IDiagnosticAnalyzer CreateAnalyzerWithinCompilation(Compilation compilation, AnalyzerOptions options, CancellationToken cancellationToken)
        {
            var specializedCollectionsSymbol = compilation.GetTypeByMetadataName(SpecializedCollectionsMetadataName);
            if (specializedCollectionsSymbol == null)
            {
                // TODO: In the future, we may want to run this analyzer even if the SpecializedCollections
                // type cannot be found in this compilation. In some cases, we may want to add a reference
                // to SpecializedCollections as a linked file or an assembly that contains it. With this
                // check, we will not warn where SpecializedCollections is not yet referenced.
                return null;
            }

            var genericEnumerableSymbol = compilation.GetTypeByMetadataName(IEnumerableMetadataName);
            if (genericEnumerableSymbol == null)
            {
                return null;
            }

            var linqEnumerableSymbol = compilation.GetTypeByMetadataName(LinqEnumerableMetadataName);
            if (linqEnumerableSymbol == null)
            {
                return null;
            }

            var genericEmptyEnumerableSymbol = linqEnumerableSymbol.GetMembers(EmptyMethodName).FirstOrDefault() as IMethodSymbol;
            if (genericEmptyEnumerableSymbol == null ||
                genericEmptyEnumerableSymbol.Arity != 1 ||
                genericEmptyEnumerableSymbol.Parameters.Length != 0)
            {
                return null;
            }

            return GetCodeBlockStartedAnalyzer(genericEnumerableSymbol, genericEmptyEnumerableSymbol);
        }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:34,代码来源:SpecializedEnumerableCreationAnalyzer.cs


示例12: CreateAnalyzerWithinCompilation

        public IDiagnosticAnalyzer CreateAnalyzerWithinCompilation(Compilation compilation, AnalyzerOptions options, CancellationToken cancellationToken)
        {
            var eventHandler = WellKnownTypes.EventHandler(compilation);
            if (eventHandler == null)
            {
                return null;
            }

            var genericEventHandler = WellKnownTypes.GenericEventHandler(compilation);
            if (genericEventHandler == null)
            {
                return null;
            }

            var eventArgs = WellKnownTypes.EventArgs(compilation);
            if (eventArgs == null)
            {
                return null;
            }

            var comSourceInterfacesAttribute = WellKnownTypes.ComSourceInterfaceAttribute(compilation);
            if (comSourceInterfacesAttribute == null)
            {
                return null;
            }

            return GetAnalyzer(compilation, eventHandler, genericEventHandler, eventArgs, comSourceInterfacesAttribute);
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:28,代码来源:CA1003DiagnosticAnalyzer.cs


示例13: AnalyzeCodeBlock

 public void AnalyzeCodeBlock(SyntaxNode codeBlock, ISymbol ownerSymbol, SemanticModel semanticModel, Action<Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
 {
     if (IsEmptyFinalizer(codeBlock, semanticModel))
     {
         addDiagnostic(ownerSymbol.CreateDiagnostic(Rule));
     }
 }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:7,代码来源:CA1821DiagnosticAnalyzer.cs


示例14: AnalyzerAndOptions

            public AnalyzerAndOptions(DiagnosticAnalyzer analyzer, AnalyzerOptions analyzerOptions)
            {
                Debug.Assert(analyzer != null);
                Debug.Assert(analyzerOptions != null);

                Analyzer = analyzer;
                _analyzerOptions = analyzerOptions;
            }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:8,代码来源:AnalyzerManager.AnalyzerAndOptions.cs


示例15: CompilationWithAnalyzersOptions

 /// <summary>
 /// Creates a new <see cref="CompilationWithAnalyzersOptions"/>.
 /// </summary>
 /// <param name="options">Options that are passed to analyzers.</param>
 /// <param name="onAnalyzerException">Action to invoke if an analyzer throws an exception.</param>
 /// <param name="concurrentAnalysis">Flag indicating whether analysis can be performed concurrently on multiple threads.</param>
 /// <param name="logAnalyzerExecutionTime">Flag indicating whether analyzer execution time should be logged.</param>
 /// <param name="reportDiagnosticsWithSourceSuppression">Flag indicating whether analyzer diagnostics with <see cref="Diagnostic.IsSuppressed"/> should be reported.</param>
 public CompilationWithAnalyzersOptions(AnalyzerOptions options, Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException, bool concurrentAnalysis, bool logAnalyzerExecutionTime, bool reportDiagnosticsWithSourceSuppression)
 {
     _options = options;
     _onAnalyzerException = onAnalyzerException;
     _concurrentAnalysis = concurrentAnalysis;
     _logAnalyzerExecutionTime = logAnalyzerExecutionTime;
     _reportDiagnosticsWithSourceSuppression = reportDiagnosticsWithSourceSuppression;
 }
开发者ID:redjbishop,项目名称:roslyn,代码行数:16,代码来源:CompilationWithAnalyzersOptions.cs


示例16: CompilationWithAnalyzersOptions

 /// <summary>
 /// Creates a new <see cref="CompilationWithAnalyzersOptions"/>.
 /// </summary>
 /// <param name="options">Options that are passed to analyzers.</param>
 /// <param name="onAnalyzerException">Action to invoke if an analyzer throws an exception.</param>
 /// <param name="concurrentAnalysis">Flag indicating whether analysis can be performed concurrently on multiple threads.</param>
 /// <param name="logAnalyzerExecutionTime">Flag indicating whether analyzer execution time should be logged.</param>
 public CompilationWithAnalyzersOptions(
     AnalyzerOptions options,
     Action<Exception, DiagnosticAnalyzer, Diagnostic> onAnalyzerException,
     bool concurrentAnalysis,
     bool logAnalyzerExecutionTime)
     : this(options, onAnalyzerException, concurrentAnalysis, logAnalyzerExecutionTime, reportSuppressedDiagnostics: false)
 {
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:15,代码来源:CompilationWithAnalyzersOptions.cs


示例17: GetSortedDiagnostics

 public static IOrderedEnumerable<Diagnostic> GetSortedDiagnostics(string filePath,
                                                                   DiagnosticAnalyzer analyzer,
                                                                   string settingsPath)
 {
     var options = new AnalyzerOptions(ImmutableArray.Create<AdditionalText>(new SettingsFile(settingsPath)));
     return GetSortedDiagnosticsFromDocuments(analyzer,
                                              DocumentSetCreator.CreateDocumentSetFromSources(filePath),
                                              options);
 }
开发者ID:DavidArno,项目名称:Arnolyzer,代码行数:9,代码来源:DiagnosticsGenerator.cs


示例18: AnalyzeCompilation

 public void AnalyzeCompilation(Compilation compilation, Action<Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
 {
     foreach (var item in this.fieldDisposedMap)
     {
         if (!item.Value)
         {
             addDiagnostic(item.Key.CreateDiagnostic(Rule));
         }
     }
 }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:10,代码来源:CA2213DiagnosticAnalyzer.cs


示例19: AnalyzeSymbol

        public override void AnalyzeSymbol(INamedTypeSymbol namedType, Compilation compilation, Action<Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
        {
            if (namedType.IsAbstract || namedType.IsSealed || !namedType.IsAttribute())
            {
                return;
            }

            // Non-sealed non-abstract attribute type.
            addDiagnostic(namedType.CreateDiagnostic(Rule));
        }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:10,代码来源:CA1813DiagnosticAnalyzer.cs


示例20: GetSortedDiagnosticsFromDocuments

        private static IOrderedEnumerable<Diagnostic> GetSortedDiagnosticsFromDocuments(DiagnosticAnalyzer analyzer,
                                                                                        TextDocument document,
                                                                                        AnalyzerOptions options)
        {
            var diagnostics = document.Project.GetCompilationAsync()
                                      .Result
                                      .WithAnalyzers(ImmutableArray.Create(analyzer),
                                                     options)
                                      .GetAnalyzerDiagnosticsAsync().Result;

            return SortDiagnostics(diagnostics);
        }
开发者ID:DavidArno,项目名称:Arnolyzer,代码行数:12,代码来源:DiagnosticsGenerator.cs



注:本文中的Microsoft.CodeAnalysis.Diagnostics.AnalyzerOptions类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Diagnostics.AnalyzerReference类代码示例发布时间:2022-05-26
下一篇:
C# Diagnostics.AnalyzerManager类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap