Example #1
0
        private async Task ApplyChangeAsync(
            ITextBuffer subjectBuffer,
            Document document,
            EncapsulateFieldResult result, CancellationToken cancellationToken)
        {
            var finalSolution = await result.GetSolutionAsync(cancellationToken).ConfigureAwait(false);

            var solution       = document.Project.Solution;
            var workspace      = solution.Workspace;
            var previewService = workspace.Services.GetService <IPreviewDialogService>();

            if (previewService != null)
            {
                await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

                finalSolution = previewService.PreviewChanges(
                    string.Format(EditorFeaturesResources.Preview_Changes_0, EditorFeaturesResources.Encapsulate_Field),
                    "vs.csharp.refactoring.preview",
                    EditorFeaturesResources.Encapsulate_Field_colon,
                    result.Name,
                    result.Glyph,
                    finalSolution,
                    solution);
            }

            if (finalSolution == null)
            {
                // User clicked cancel.
                return;
            }

            using var undoTransaction = _undoManager.GetTextBufferUndoManager(subjectBuffer).TextBufferUndoHistory.CreateTransaction(EditorFeaturesResources.Encapsulate_Field);

            if (workspace.TryApplyChanges(finalSolution))
            {
                undoTransaction.Complete();
            }
            else
            {
                undoTransaction.Cancel();
            }
        }
Example #2
0
 public EncapsulateFieldCodeAction(EncapsulateFieldResult result, string title)
 {
     _result = result;
     _title  = title;
 }
 public EncapsulateFieldCodeAction(EncapsulateFieldResult result, string title)
 {
     _result = result;
     _title = title;
 }
 public EncapsulateFieldCodeAction(EncapsulateFieldResult result, string title)
 {
     this.result = result;
     this.title  = title;
 }