private static void ComputeRefactoring( RefactoringContext context, MemberDeclarationSortMode sortMode, string title, MemberDeclarationSelection selectedMembers, ImmutableArray <MemberDeclarationSyntax> members) { if (!MemberDeclarationComparer.GetInstance(sortMode).IsSorted(members)) { context.RegisterRefactoring( title, cancellationToken => RefactorAsync(context.Document, selectedMembers, sortMode, cancellationToken)); } }
private static Task <Document> RefactorAsync( Document document, MemberDeclarationSelection selectedMembers, MemberDeclarationSortMode sortMode, CancellationToken cancellationToken) { MemberDeclarationComparer comparer = MemberDeclarationComparer.GetInstance(sortMode); MemberDeclarationSyntax containingMember = selectedMembers.ContainingMember; SyntaxList <MemberDeclarationSyntax> members = containingMember.GetMembers(); SyntaxList <MemberDeclarationSyntax> newMembers = members .Take(selectedMembers.StartIndex) .Concat(selectedMembers.OrderBy(f => f, comparer)) .Concat(members.Skip(selectedMembers.EndIndex + 1)) .ToSyntaxList(); MemberDeclarationSyntax newNode = containingMember.WithMembers(newMembers); return(document.ReplaceNodeAsync(containingMember, newNode, cancellationToken)); }