示例#1
0
            public override void AddSuppressOperations(List <SuppressOperation> list, SyntaxNode node, OptionSet optionSet, NextAction <SuppressOperation> nextOperation)
            {
                base.AddSuppressOperations(list, node, optionSet, nextOperation);

                // remove suppression rules for array and collection initializer
                if (node.IsInitializerForArrayOrCollectionCreationExpression())
                {
                    if (optionSet.GetOption(CSharpFormattingOptions.NewLinesForBracesInObjectInitializers))
                    {
                        // remove any suppression operation
                        list.RemoveAll(s_predicate);
                    }
                    else
                    {
                        // remove only space suppression operation.
                        for (var i = 0; i < list.Count; i++)
                        {
                            var operation = list[i];
                            if (operation.Option.IsMaskOn(SuppressOption.NoSpacing))
                            {
                                list[i] = FormattingOperations.CreateSuppressOperation(operation.StartToken, operation.EndToken, operation.Option & ~SuppressOption.NoSpacing);
                            }
                        }
                    }
                }
            }
示例#2
0
        protected void AddSuppressOperation(List <SuppressOperation> list, SyntaxToken startToken, SyntaxToken endToken, SuppressOption option)
        {
            if (startToken.Kind() == SyntaxKind.None || endToken.Kind() == SyntaxKind.None)
            {
                return;
            }

            list.Add(FormattingOperations.CreateSuppressOperation(startToken, endToken, option));
        }
        private static void AddPropertyDeclarationSuppressOperations(List <SuppressOperation> list, SyntaxNode node)
        {
            if (node is BasePropertyDeclarationSyntax basePropertyDeclaration && basePropertyDeclaration.AccessorList != null &&
                basePropertyDeclaration.AccessorList.Accessors.All(a => a.Body == null) &&
                basePropertyDeclaration.GetAnnotatedTrivia(SyntaxAnnotation.ElasticAnnotation).Any())
            {
                var tokens = basePropertyDeclaration.GetFirstAndLastMemberDeclarationTokensAfterAttributes();

                list.Add(FormattingOperations.CreateSuppressOperation(tokens.Item1, tokens.Item2, SuppressOption.NoWrapping | SuppressOption.IgnoreElasticWrapping));
            }
        }
示例#4
0
        private void SuppressVariableDeclaration(List <SuppressOperation> list, SyntaxNode node, OptionSet optionSet)
        {
            if (node.IsKind(SyntaxKind.FieldDeclaration) || node.IsKind(SyntaxKind.EventDeclaration) ||
                node.IsKind(SyntaxKind.EventFieldDeclaration) || node.IsKind(SyntaxKind.LocalDeclarationStatement))
            {
                if (optionSet.GetOption(CSharpFormattingOptions.SpacesIgnoreAroundVariableDeclaration))
                {
                    var firstToken = node.GetFirstToken(includeZeroWidth: true);
                    var lastToken  = node.GetLastToken(includeZeroWidth: true);

                    list.Add(FormattingOperations.CreateSuppressOperation(firstToken, lastToken, SuppressOption.NoSpacing));
                }
            }
        }