Ejemplo n.º 1
0
        static void AnalyzeFieldDeclaration(SyntaxNodeAnalysisContext context, FieldDeclarationSyntax fieldDeclarationSyntax, ITypeSymbol enumerableTypeSymbol)
        {
            if (fieldDeclarationSyntax.IsPublic())
            {
                return;
            }

            var typeSyntax    = fieldDeclarationSyntax.Declaration.Type;
            var semanticModel = context.SemanticModel;
            var typeSymbol    = semanticModel.GetTypeInfo(typeSyntax).Type;

            if (typeSymbol is null ||
                !IsEnumerableType(typeSymbol, context.Compilation, out var enumeratorType) ||
                enumeratorType.IsValueType)
            {
                return;
            }

            var diagnostic = Diagnostic.Create(Rule, typeSyntax.GetLocation(), enumerableTypeSymbol.MetadataName, typeSymbol.MetadataName);

            context.ReportDiagnostic(diagnostic);
        }
Ejemplo n.º 2
0
 bool CheckVisibility(FieldDeclarationSyntax baseFieldFieldDeclaration, AccessorDeclarationSyntax getNode, AccessorDeclarationSyntax setNode, PropertyDeclarationSyntax propertyDeclaration)
 {
     if (baseFieldFieldDeclaration.IsPrivate())
     {
         return(true);
     }
     else
     {
         if (baseFieldFieldDeclaration.IsPublic())
         {
             if (propertyDeclaration.IsPublic() == false)
             {
                 return(false);
             }
             if (getNode.Modifiers.Any())
             {
                 return(false);
             }
             if (setNode.Modifiers.Any())
             {
                 return(false);
             }
         }
         else if (baseFieldFieldDeclaration.IsProtected())
         {
             if (propertyDeclaration.IsPrivate() == false)
             {
                 return(false);
             }
             if (propertyDeclaration.IsProtected())
             {
                 if (getNode.Modifiers.Any())
                 {
                     return(false);
                 }
                 if (setNode.Modifiers.Any())
                 {
                     return(false);
                 }
             }
             else if (propertyDeclaration.IsPublic())
             {
                 if (baseFieldFieldDeclaration.IsInternal() == false)
                 {
                     if (getNode.Modifiers.Any(x => x.IsKind(SyntaxKind.PrivateKeyword) || x.IsKind(SyntaxKind.InternalKeyword)))
                     {
                         return(false);
                     }
                     if (setNode.Modifiers.Any(x => x.IsKind(SyntaxKind.PrivateKeyword) || x.IsKind(SyntaxKind.InternalKeyword)))
                     {
                         return(false);
                     }
                 }
                 else
                 {
                     if (getNode.Modifiers.Any(x => x.IsKind(SyntaxKind.PrivateKeyword)))
                     {
                         return(false);
                     }
                     if (setNode.Modifiers.Any(x => x.IsKind(SyntaxKind.PrivateKeyword)))
                     {
                         return(false);
                     }
                 }
             }
         }
         else if (baseFieldFieldDeclaration.IsInternal())
         {
             if (propertyDeclaration.IsPrivate() == false)
             {
                 return(false);
             }
             if (propertyDeclaration.IsInternal())
             {
                 if (getNode.Modifiers.Any())
                 {
                     return(false);
                 }
                 if (setNode.Modifiers.Any())
                 {
                     return(false);
                 }
             }
             else if (propertyDeclaration.IsPublic())
             {
                 if (getNode.Modifiers.Any(x => x.IsKind(SyntaxKind.PrivateKeyword) || x.IsKind(SyntaxKind.ProtectedKeyword)))
                 {
                     return(false);
                 }
                 if (setNode.Modifiers.Any(x => x.IsKind(SyntaxKind.PrivateKeyword) || x.IsKind(SyntaxKind.ProtectedKeyword)))
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
Ejemplo n.º 3
0
 public static bool IsRecordViable(this FieldDeclarationSyntax field)
 {
     return(field.IsPublic() && !field.IsStatic());
 }