예제 #1
0
        public string Apply(ApplyContentEventArgs ea, string selectedProjectName)
        {
            Project project = _projectServices.GetProject(selectedProjectName);

            IEnumerable <NamespaceReference> namespaceReferences = _namespaceServices.BuildNamespaceReferences(ea.Element);
            Namespace       namespaceScope  = new Namespace(_namespaceServices.GetNamespaceForElement(ea.Element));
            TypeDeclaration typeDeclaration = GetTypeDeclarationForElement(ea.Element);

            if (typeDeclaration != null)
            {
                DeleteTypeDeclaration(typeDeclaration);
            }

            string code = BuildCode(namespaceReferences, namespaceScope, typeDeclaration);

            return(WriteCodeToNewFileInProject(project, code, ea.Element.Name));
        }
        public void Apply(ApplyContentEventArgs ea, string selectedProjectName)
        {
            Project selectedProject = _projectServices.GetProject(selectedProjectName);

            string filename = _projectServices.GetUniqueFilepathForNewFileInProject(selectedProject, ea.Element.Name);

            //selectedProject.CodeModel.DTE.ItemOperations.AddNewItem(@"Visual C# Items\Code\Class", filename);

            var currentProject          = DevExpress.CodeRush.Core.SolutionHelper.GetProjectByName(CodeRush.Project.Active.Name);
            var projectToAddAsReference = DevExpress.CodeRush.Core.SolutionHelper.GetProjectByName(selectedProjectName);

            currentProject.CodeModel.DTE.ItemOperations.AddNewItem(@"Visual C# Items\Code\Class", filename);

            var vsProj = currentProject.Object as VSLangProj.VSProject;

            if (vsProj != null)
            {
                vsProj.References.AddProject(projectToAddAsReference);
            }
        }