private static SyntaxTokenList UpdateDeclarationAccessibility(SyntaxTokenList modifiersList, Accessibility newAccessibility, CodeGenerationOptions options)
        {
            var newModifierTokens = new List <SyntaxToken>();

            CSharpCodeGenerationHelpers.AddAccessibilityModifiers(newAccessibility, newModifierTokens, options, Accessibility.NotApplicable);
            if (newModifierTokens.Count == 0)
            {
                return(modifiersList);
            }

            return(GetUpdatedDeclarationAccessibilityModifiers(newModifierTokens, modifiersList, (SyntaxToken modifier) => SyntaxFacts.IsAccessibilityModifier(modifier.Kind()))
                   .ToSyntaxTokenList());
        }
Exemple #2
0
        private static MemberDeclarationSyntax LastField(
            SyntaxList <MemberDeclarationSyntax> members,
            FieldDeclarationSyntax fieldDeclaration)
        {
            var lastConst = members.AsEnumerable()
                            .OfType <FieldDeclarationSyntax>()
                            .Where(f => f.Modifiers.Any(SyntaxKind.ConstKeyword)).LastOrDefault();

            // Place a const after the last existing const.
            if (fieldDeclaration.Modifiers.Any(SyntaxKind.ConstKeyword))
            {
                return(lastConst);
            }

            // Place a field after the last field, or after the last const.
            return(CSharpCodeGenerationHelpers.LastField(members) ?? lastConst);
        }
        private static SyntaxTokenList UpdateDeclarationAccessibility(SyntaxTokenList modifiersList, Accessibility newAccessibility, CodeGenerationOptions options)
        {
            var newModifierTokens = ArrayBuilder <SyntaxToken> .GetInstance();

            CSharpCodeGenerationHelpers.AddAccessibilityModifiers(newAccessibility, newModifierTokens, options, Accessibility.NotApplicable);
            if (newModifierTokens.Count == 0)
            {
                return(modifiersList);
            }

            // TODO: Move more APIs to use pooled ArrayBuilder
            // https://github.com/dotnet/roslyn/issues/34960
            var list = newModifierTokens.ToList();

            newModifierTokens.Free();
            return(GetUpdatedDeclarationAccessibilityModifiers(list, modifiersList, (SyntaxToken modifier) => SyntaxFacts.IsAccessibilityModifier(modifier.Kind()))
                   .ToSyntaxTokenList());
        }
 public override CodeGenerationDestination GetDestination(SyntaxNode node)
 {
     return(CSharpCodeGenerationHelpers.GetDestination(node));
 }
 public override CodeGenerationDestination GetDestination(SyntaxNode node)
 => CSharpCodeGenerationHelpers.GetDestination(node);