protected override bool IsValidContext(
            int position,
            CSharpSyntaxContext context,
            CancellationToken cancellationToken
            )
        {
            if (
                context.IsMemberAttributeContext(
                    SyntaxKindSet.ClassInterfaceStructRecordTypeDeclarations,
                    cancellationToken
                    )
                )
            {
                return(true);
            }

            var token = context.TargetToken;

            if (
                token.Kind() == SyntaxKind.OpenBracketToken &&
                token.Parent.IsKind(SyntaxKind.AttributeList)
                )
            {
                if (
                    token.GetAncestor <PropertyDeclarationSyntax>() != null ||
                    token.GetAncestor <EventDeclarationSyntax>() != null
                    )
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
 private static bool IsAttributeContext(CSharpSyntaxContext context, CancellationToken cancellationToken)
 {
     return
         (context.IsMemberAttributeContext(SyntaxKindSet.ClassInterfaceStructTypeDeclarations, cancellationToken) ||
          (context.SyntaxTree.IsScript() && context.IsTypeAttributeContext(cancellationToken)) ||
          context.IsStatementAttributeContext());
 }
Exemple #3
0
        protected override bool IsValidContext(
            int position,
            CSharpSyntaxContext context,
            CancellationToken cancellationToken
            )
        {
            var syntaxTree = context.SyntaxTree;

            return((context.IsGlobalStatementContext && syntaxTree.IsScript()) ||
                   syntaxTree.IsGlobalMemberDeclarationContext(
                       position,
                       SyntaxKindSet.AllGlobalMemberModifiers,
                       cancellationToken
                       ) ||
                   context.IsMemberDeclarationContext(
                       validModifiers: s_validClassModifiers,
                       validTypeDeclarations: SyntaxKindSet.ClassInterfaceRecordTypeDeclarations,
                       canBePartial: false,
                       cancellationToken: cancellationToken
                       ) ||
                   context.IsMemberDeclarationContext(
                       validModifiers: s_validStructModifiers,
                       validTypeDeclarations: SyntaxKindSet.StructOnlyTypeDeclarations,
                       canBePartial: false,
                       cancellationToken: cancellationToken
                       ) ||
                   context.IsMemberAttributeContext(
                       SyntaxKindSet.ClassInterfaceStructRecordTypeDeclarations,
                       cancellationToken
                       ));
        }
Exemple #4
0
 protected override bool IsValidContext(
     int position,
     CSharpSyntaxContext context,
     CancellationToken cancellationToken
     ) =>
 context.IsMemberAttributeContext(
     SyntaxKindSet.ClassInterfaceStructRecordTypeDeclarations,
     cancellationToken
     );
Exemple #5
0
 protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
 {
     return(context.IsMemberAttributeContext(s_validTypeDeclarations, cancellationToken));
 }