コード例 #1
0
        private async Task RenameAsync(string soureCode, string oldFilePath, string newFilePath)
        {
            using (var ws = new AdhocWorkspace())
            {
                var      projectId = ProjectId.CreateNewId();
                Solution solution  = ws.AddSolution(InitializeWorkspace(projectId, newFilePath, soureCode));
                Project  project   = (from d in solution.Projects where d.Id == projectId select d).FirstOrDefault();

                var userNotificationServices = IUserNotificationServicesFactory.Implement(f => ConfirmRename(""));
                var optionsSettingsFactory   = IOptionsSettingsFactory.Implement((string category, string page, string property, bool defaultValue) => { return(true); });

                var renamer = new Renamer(ws, IProjectThreadingServiceFactory.Create(), userNotificationServices, optionsSettingsFactory, null, project, oldFilePath, newFilePath);
                await renamer.RenameAsync(project);
            }
        }
コード例 #2
0
        private async Task ScheduleRenameAsync(string oldFilePath, string newFilePath)
        {
            string codeExtension = Path.GetExtension(newFilePath);

            if (codeExtension == null || !oldFilePath.EndsWith(codeExtension, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            await _projectVsServices.ThreadingService.SwitchToUIThread();

            var myProject = _visualStudioWorkspace
                            .CurrentSolution
                            .Projects.Where(p => StringComparers.Paths.Equals(p.FilePath, _projectVsServices.Project.FullPath))
                            .FirstOrDefault();

            var renamer = new Renamer(_visualStudioWorkspace, _projectVsServices.ThreadingService, _userNotificationServices, _optionsSettings, _roslynServices, myProject, oldFilePath, newFilePath);

            _visualStudioWorkspace.WorkspaceChanged += renamer.OnWorkspaceChangedAsync;
        }