/// <summary> /// Removes the comments. /// </summary> /// <param name="instance">The instance.</param> public static void RemoveComments(this ProjectItem instance) { TraceService.WriteLine("ProjectItemExtensions::RemoveComments Name=" + instance.Name); if (instance.IsCSharpFile()) { CodeClass codeClass = instance.GetFirstClass(); if (codeClass != null) { instance.GetFirstClass().RemoveComments(); } } //// don't forget sub items. if (instance.ProjectItems != null) { instance.GetCSharpProjectItems() .ToList() .ForEach(x => x.RemoveComments()); instance.GetXamlProjectItems() .ToList() .ForEach(x => x.RemoveComments()); } }
/// <summary> /// Removes the header. /// </summary> /// <param name="instance">The instance.</param> public static void RemoveHeader(this ProjectItem instance) { TraceService.WriteLine("ProjectItemExtensions::RemoveHeader Name=" + instance.Name); if (instance.IsCSharpFile()) { Window window = instance.Open(VSConstants.VsViewKindCode); if (window != null) { try { window.Activate(); } catch (Exception exception) { ///// i think this happens when i am debugging (i could be wrong!) TraceService.WriteError("Cant Remove Header Window Activate wont work exception=" + exception.Message); return; } TextSelection selection = (TextSelection)instance.Document.Selection; bool continueLoop = true; int loopCounter = 0; do { //// just in case we get infinity loop problem! if (loopCounter > 100) { TraceService.WriteLine("breaking out of loop"); continueLoop = false; } selection.GotoLine(1, true); selection.SelectLine(); TraceService.WriteLine("text=" + selection.Text); if (selection.Text.TrimStart().StartsWith("//")) { TraceService.WriteLine("*** deleting selection"); selection.Delete(); loopCounter++; } else { TraceService.WriteLine("*** NOT deleting selection"); continueLoop = false; } }while (continueLoop); } } //// don't forget sub items. if (instance.ProjectItems != null) { IEnumerable <ProjectItem> subProjectItems = instance.GetCSharpProjectItems(); foreach (ProjectItem subProjectItem in subProjectItems) { subProjectItem.RemoveHeader(); } } }