示例#1
0
        public static bool DoUpdateOnWorkspace <TChange>(Workspace workspace,
                                                         Func <IRoot, IEnumerable <TChange> > getItems,
                                                         IUpdateRefactoring <TChange> updateRefactoring)
            where TChange : IDom
        {
            var solution = workspace.CurrentSolution;
            //var changedDocuments = ChangeAll(solution);
            //foreach(var document in changedDocuments )
            //{
            //   solution = solution.WithDocumentSyntaxRoot(document.Id, document);
            //   workspace.TryApplyChanges(solution);

            //}

            var didAnythingChange = false;
            var newSolution       = DoUpdateOnSolution(solution, ref didAnythingChange, getItems, updateRefactoring);

            if (didAnythingChange)
            {
                if (workspace.TryApplyChanges(solution))
                {
                    return(true);
                }
            }
            return(didAnythingChange);
        }
示例#2
0
 public static bool DoUpdateOnFiles <TChange>(IEnumerable <Tuple <string, string> > filePairs,
                                              Func <IRoot, IEnumerable <TChange> > getItems,
                                              IUpdateRefactoring <TChange> updateRefactoring)
     where TChange : IDom
 {
     return(DoUpdateOnFiles(filePairs, getItems, updateRefactoring.NeedsChange, updateRefactoring.MakeChange));
 }
示例#3
0
        public static SyntaxTree DoUpdateOnDocument <TChange>(Document document,
                                                              Func <IRoot, IEnumerable <TChange> > getItems,
                                                              IUpdateRefactoring <TChange> updateRefactoring)
            where TChange : IDom
        {
            var        didThisChange = false;
            SyntaxTree tree;

            if (document.TryGetSyntaxTree(out tree))
            {
                var newTree = UpdateTree(tree, ref didThisChange, getItems, updateRefactoring.NeedsChange, updateRefactoring.MakeChange);
                if (didThisChange)
                {
                    return(newTree);
                }
            }
            return(null);
        }
示例#4
0
        public static Solution DoUpdateOnProject <TChange>(Project project, Solution solution, ref bool didChange,
                                                           Func <IRoot, IEnumerable <TChange> > getItems,
                                                           IUpdateRefactoring <TChange> updateRefactoring)
            where TChange : IDom
        {
            var documents   = project.Documents.Where(x => x.SupportsSyntaxTree);
            var newSolution = solution;

            foreach (var document in documents)
            {
                var id            = document.Id;
                var newSyntaxTree = DoUpdateOnDocument(document, getItems, updateRefactoring);
                if (newSyntaxTree != null)
                {
                    didChange   = true;
                    newSolution = newSolution.WithDocumentSyntaxRoot(id, newSyntaxTree.GetCompilationUnitRoot());
                }
            }
            return(newSolution);
        }
示例#5
0
        //private static IEnumerable<Document> ChangeAll(Solution solution)
        //{
        //   throw new NotImplementedException();
        //}

        public static Solution DoUpdateOnSolution <TChange>(Solution solution, ref bool didAnythingChange,
                                                            Func <IRoot, IEnumerable <TChange> > getItems,
                                                            IUpdateRefactoring <TChange> updateRefactoring)
            where TChange : IDom
        {
            var projects    = solution.Projects.Where(x => x.Language == ExpectedLanguages.CSharp);
            var newSolution = solution;

            foreach (var project in projects)
            {
                var didThisChange = false;
                newSolution = DoUpdateOnProject(project, newSolution, ref didThisChange, getItems, updateRefactoring);
                if (didThisChange)
                {
                    didAnythingChange = true;
                }
            }

            return(newSolution);
        }