当前位置: 首页>>代码示例>>C#>>正文


C# SymbolAnalysisContext.IsGenerated方法代码示例

本文整理汇总了C#中SymbolAnalysisContext.IsGenerated方法的典型用法代码示例。如果您正苦于以下问题:C# SymbolAnalysisContext.IsGenerated方法的具体用法?C# SymbolAnalysisContext.IsGenerated怎么用?C# SymbolAnalysisContext.IsGenerated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SymbolAnalysisContext的用法示例。


在下文中一共展示了SymbolAnalysisContext.IsGenerated方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Analyze

        private static void Analyze(SymbolAnalysisContext context)
        {
            if (context.IsGenerated()) return;
            var symbol = (INamedTypeSymbol)context.Symbol;
            if (symbol.TypeKind != TypeKind.Class) return;
            if (!symbol.Interfaces.Any(i => i.SpecialType == SpecialType.System_IDisposable)) return;
            if (symbol.IsSealed && !ContainsUserDefinedFinalizer(symbol)) return;
            if (!ContainsNonPrivateConstructors(symbol)) return;
            var disposeMethod = FindDisposeMethod(symbol);
            if (disposeMethod == null) return;
            var syntaxTree = disposeMethod.DeclaringSyntaxReferences[0]?.GetSyntax();

            var statements = ((MethodDeclarationSyntax)syntaxTree)?.Body?.Statements.OfType<ExpressionStatementSyntax>();
            if (statements != null)
            {
                foreach (var statement in statements)
                {
                    var invocation = statement.Expression as InvocationExpressionSyntax;
                    var method = invocation?.Expression as MemberAccessExpressionSyntax;
                    var identifierSyntax = method?.Expression as IdentifierNameSyntax;
                    if (identifierSyntax != null && identifierSyntax.Identifier.ToString() == "GC" && method.Name.ToString() == "SuppressFinalize")
                        return;
                }
            }
            context.ReportDiagnostic(Diagnostic.Create(Rule, disposeMethod.Locations[0], symbol.Name));
        }
开发者ID:Bemjamin,项目名称:code-cracker,代码行数:26,代码来源:DisposablesShouldCallSuppressFinalizeAnalyzer.cs

示例2: Analyze

        private static void Analyze(SymbolAnalysisContext context)
        {
            if (context.IsGenerated()) return;
            var type = (INamedTypeSymbol)context.Symbol;

            if (type.TypeKind != TypeKind.Class) return;

            if (!IsAttribute(type)) return;

            if (type.IsAbstract || type.IsSealed) return;

            context.ReportDiagnostic(Diagnostic.Create(Rule, type.Locations[0], type.Name));
        }
开发者ID:JeanLLopes,项目名称:code-cracker,代码行数:13,代码来源:SealedAttributeAnalyzer.cs

示例3: AnalyzeField

 private static void AnalyzeField(SymbolAnalysisContext context)
 {
     if (context.IsGenerated()) return;
     var fieldSymbol = (IFieldSymbol)context.Symbol;
     if (!fieldSymbol.Type.AllInterfaces.Any(i => i.ToString() == "System.IDisposable") && fieldSymbol.Type.ToString() != "System.IDisposable") return;
     var fieldSyntaxRef = fieldSymbol.DeclaringSyntaxReferences.FirstOrDefault();
     var variableDeclarator = fieldSyntaxRef.GetSyntax() as VariableDeclaratorSyntax;
     if (variableDeclarator == null) return;
     if (ContainingTypeImplementsIDisposableAndCallsItOnTheField(context, fieldSymbol, fieldSymbol.ContainingType)) return;
     var props = new Dictionary<string, string> { { "variableIdentifier", variableDeclarator.Identifier.ValueText } }.ToImmutableDictionary();
     if (variableDeclarator.Initializer?.Value is InvocationExpressionSyntax)
         context.ReportDiagnostic(Diagnostic.Create(RuleForReturned, variableDeclarator.GetLocation(), props, fieldSymbol.Name));
     else if (variableDeclarator.Initializer?.Value is ObjectCreationExpressionSyntax)
         context.ReportDiagnostic(Diagnostic.Create(RuleForCreated, variableDeclarator.GetLocation(), props, fieldSymbol.Name));
 }
开发者ID:Cadums01,项目名称:code-cracker,代码行数:15,代码来源:DisposableFieldNotDisposedAnalyzer.cs


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