コード例 #1
0
        private static void AnalyzeSymbol(SymbolAnalysisContext context, ImmutableTypes immutableTypes)
        {
            immutableTypes.Initialize(context.Compilation, context.Options, context.CancellationToken);

            var symbol         = (IFieldSymbol)context.Symbol;
            var containingType = symbol.ContainingType;

            if (containingType == null)
            {
                return;
            }

            string genericTypeArgument = null;

            if (Helper.HasImmutableAttributeAndShouldVerify(containingType) &&
                Helper.ShouldCheckMemberTypeForImmutability(symbol) &&
                !immutableTypes.IsImmutableType(symbol.Type, ref genericTypeArgument))
            {
                if (genericTypeArgument != null)
                {
                    var diagnostic = Diagnostic.Create(RuleGeneric, symbol.Locations[0], symbol.Name, genericTypeArgument);
                    context.ReportDiagnostic(diagnostic);
                }
                else
                {
                    var diagnostic = Diagnostic.Create(Rule, symbol.Locations[0], symbol.Name);
                    context.ReportDiagnostic(diagnostic);
                }
            }
        }
コード例 #2
0
ファイル: IMM006.cs プロジェクト: mwelsh1118/Apex.Analyzers
        private static void AnalyzeSymbol(SymbolAnalysisContext context, ImmutableTypes immutableTypes)
        {
            immutableTypes.Initialize(context.Compilation, context.Options, context.CancellationToken);

            string genericTypeArgument = null;
            var    symbol = (INamedTypeSymbol)context.Symbol;

            if (symbol.BaseType != null &&
                Helper.HasImmutableAttributeAndShouldVerify(symbol) &&
                !immutableTypes.IsImmutableType(symbol.BaseType, ref genericTypeArgument))
            {
                var diagnostic = Diagnostic.Create(Rule, symbol.Locations[0], symbol.Name);
                context.ReportDiagnostic(diagnostic);
            }
        }