'' Version 1.3. Upgraded by Laurentiu Macovei (laurentiu.macovei@dotnetwise.com) '' 25/05/2009 '' '' Make sure you are refferencing System.Web '' and import the following namespaces: '' '' Imports System.Collections '' Imports System.Text '' Imports System.Text.RegularExpressions Public Sub CommentWholeCode() PutInRegions(True, Environment.UserName, Nothing, False) End Sub 'just comments the code with specified user name AndAlso date Public Sub CommentWholeCodeSpecific() PutInRegions(True, "john.doe", "2010", False) End Sub Public Sub CommentWholeCodeSpecific2() PutInRegions(True, "[CreatedUserName]", "[CreatedDate]", False) End Sub 'move code into regions AndAlso comments with the 0 Threading.Thread.Sleep(1) Application.DoEvents() ms -= 1 End While End Sub Public Sub RemoveCreatedByComments() Dim Find_Action = DTE.Find.Action Dim Find_Backwards = DTE.Find.Backwards Dim Find_FilesOfType = DTE.Find.FilesOfType Dim Find_FindWhat = DTE.Find.FindWhat Dim Find_KeepModifiedDocumentsOpen = DTE.Find.KeepModifiedDocumentsOpen Dim Find_MatchCase = DTE.Find.MatchCase Dim Find_MatchInHiddenText = DTE.Find.MatchInHiddenText Dim Find_MatchWholeWord = DTE.Find.MatchWholeWord Dim Find_PatternSyntax = DTE.Find.PatternSyntax Dim Find_ReplaceWith = DTE.Find.ReplaceWith Dim Find_ResultsLocation = DTE.Find.ResultsLocation Dim Find_SearchPath = DTE.Find.SearchPath Dim Find_SearchSubfolders = DTE.Find.SearchSubfolders Dim Find_Target = DTE.Find.Target If (String.IsNullOrEmpty(Find_FindWhat)) Then Find_FindWhat = "author" End If Try DTE.UndoContext.Open("Remove created by comments") DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr DTE.Find.FindWhat = "^(.*)\/\/\/\ \ selection.Text.LastIndexOf(vbLf) Then DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocumentSelection Else DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument End If DTE.Find.MatchCase = False DTE.Find.MatchWholeWord = False DTE.Find.MatchInHiddenText = True DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone DTE.Find.Action = vsFindAction.vsFindActionReplaceAll DTE.Find.Execute() DTE.Windows.Item("{CF2DDC32-8CAD-11D2-9302-005345000000}").Close() Finally DTE.UndoContext.Close() DTE.Find.Action = Find_Action DTE.Find.Backwards = Find_Backwards DTE.Find.FilesOfType = Find_FilesOfType DTE.Find.FindWhat = Find_FindWhat DTE.Find.KeepModifiedDocumentsOpen = Find_KeepModifiedDocumentsOpen DTE.Find.MatchCase = Find_MatchCase DTE.Find.MatchInHiddenText = Find_MatchInHiddenText DTE.Find.MatchWholeWord = Find_MatchWholeWord DTE.Find.PatternSyntax = Find_PatternSyntax DTE.Find.ReplaceWith = Find_ReplaceWith DTE.Find.Results DTE.Find.SearchPath = Find_SearchPath DTE.Find.SearchSubfolders = Find_SearchSubfolders DTE.Find.Target = Find_Target End Try End Sub Sub PutInRegions(ByVal includeCreatedAuthorComment As Boolean, Optional ByVal commentUserName As String = Nothing, Optional ByVal commentDateStamp As String = Nothing, Optional ByVal moveInRegions As Boolean = True) Dim projectItem As ProjectItem Dim fileCodeModel As FileCodeModel Dim regionFields As EditPoint Dim editPoint As EditPoint Dim commentStart As String projectItem = DTE.ActiveDocument.ProjectItem fileCodeModel = projectItem.FileCodeModel If (commentUserName Is Nothing) Then commentUserName = Environment.UserName End If '' For the sample, don't bother recursively descending all code like '' the OutlineCode sample does. Just get a first CodeType in the '' file. Dim Find_Action = DTE.Find.Action Dim Find_Backwards = DTE.Find.Backwards Dim Find_FilesOfType = DTE.Find.FilesOfType Dim Find_FindWhat = DTE.Find.FindWhat Dim Find_KeepModifiedDocumentsOpen = DTE.Find.KeepModifiedDocumentsOpen Dim Find_MatchCase = DTE.Find.MatchCase Dim Find_MatchInHiddenText = DTE.Find.MatchInHiddenText Dim Find_MatchWholeWord = DTE.Find.MatchWholeWord Dim Find_PatternSyntax = DTE.Find.PatternSyntax Dim Find_ReplaceWith = DTE.Find.ReplaceWith Dim Find_ResultsLocation = DTE.Find.ResultsLocation Dim Find_SearchPath = DTE.Find.SearchPath Dim Find_SearchSubfolders = DTE.Find.SearchSubfolders Dim Find_Target = DTE.Find.Target If (String.IsNullOrEmpty(Find_FindWhat)) Then Find_FindWhat = "author" End If Try DTE.UndoContext.Open("Group Members in Regions") 'For Each p As EnvDTE.Project In DTE.Solution.Projects ' ParseProjectNode(p) 'Next DTE.SuppressUI = True ParseUsings(moveInRegions, fileCodeModel.CodeElements) For Each namespaceCodeElement As CodeElement In fileCodeModel.CodeElements ParseNamespaceElement(namespaceCodeElement, includeCreatedAuthorComment, commentUserName, commentDateStamp, moveInRegions, True) Next If (moveInRegions) Then DTE.Find.FindWhat = "{ [\+\-]\= }new .+\({.+}\)" DTE.Find.ReplaceWith = "\1\2" DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument DTE.Find.MatchCase = False DTE.Find.MatchWholeWord = False DTE.Find.MatchInHiddenText = True DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr DTE.Find.SearchPath = "Current Document" DTE.Find.SearchSubfolders = True DTE.Find.KeepModifiedDocumentsOpen = False DTE.Find.FilesOfType = "" DTE.Find.Action = vsFindAction.vsFindActionReplaceAll DTE.Find.Execute() End If Catch ex As Exception MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Finally DTE.SuppressUI = False DTE.UndoContext.Close() DTE.Find.Action = Find_Action DTE.Find.Backwards = Find_Backwards DTE.Find.FilesOfType = Find_FilesOfType DTE.Find.FindWhat = Find_FindWhat DTE.Find.KeepModifiedDocumentsOpen = Find_KeepModifiedDocumentsOpen DTE.Find.MatchCase = Find_MatchCase DTE.Find.MatchInHiddenText = Find_MatchInHiddenText DTE.Find.MatchWholeWord = Find_MatchWholeWord DTE.Find.PatternSyntax = Find_PatternSyntax DTE.Find.ReplaceWith = Find_ReplaceWith DTE.Find.Results DTE.Find.SearchPath = Find_SearchPath DTE.Find.SearchSubfolders = Find_SearchSubfolders DTE.Find.Target = Find_Target If (moveInRegions) Then Dim sel As TextSelection = DTE.ActiveDocument.Selection Dim p As TextPoint = sel.TextRanges().Item(1).StartPoint sel.SelectAll() sel.SmartFormat() sel.MoveToPoint(p, False) End If End Try End Sub Sub ParseUsings(ByVal moveInRegions As Boolean, ByVal codeElements As CodeElements) If (True Or moveInRegions) Then Dim isFirstUsing = True Dim t As EditPoint Dim usings As System.Collections.Generic.List(Of String) = New System.Collections.Generic.List(Of String)() For Each namespaceCodeElement As CodeElement In codeElements If (namespaceCodeElement.Kind = vsCMElement.vsCMElementImportStmt) Then If (isFirstUsing) Then isFirstUsing = False t = namespaceCodeElement.GetStartPoint().CreateEditPoint() End If Dim p As EditPoint = namespaceCodeElement.GetStartPoint().CreateEditPoint() Dim e As TextPoint = namespaceCodeElement.GetEndPoint() Dim s As String = p.GetText(e) If (s.EndsWith(";")) Then s = s.Remove(s.Length - 1, 1) End If usings.Add(s) p.Delete(e) If (p.GetText(1) = vbCrLf) Then p.Delete(1) End If End If Next usings.Sort() Dim usingSystem As String = "using System" If (usings.Contains(usingSystem)) Then t.Insert(usingSystem + ";" + vbCrLf) End If For Each u As String In usings If (u <> usingSystem AndAlso u.StartsWith("using System.")) Then t.Insert(u + ";" + vbCrLf) End If Next For Each u As String In usings If (u <> usingSystem And Not u.StartsWith("using System.")) Then t.Insert(u + ";" + vbCrLf) End If Next End If End Sub Private Sub ParseProjectNode(ByVal parentPrject As Project) For Each p As ProjectItem In parentPrject.ProjectItems If (p.SubProject() IsNot Nothing) Then ParseProjectNode(p.SubProject) Else Try If (p.ProjectItems IsNot Nothing) Then ParseItemsNode(p.ProjectItems) End If Catch ex As Exception Throw New Exception("The name of the failure project item is: '" + p.Name + "'", ex) End Try End If Next End Sub Sub ParseItemsNode(ByVal itemsToParse As ProjectItems) For Each i As ProjectItem In itemsToParse Dim keyword = ".Designer." If (i.Name = "zx.cs") Then keyword = keyword End If If (i.ProjectItems IsNot Nothing AndAlso i.ProjectItems.Count > 0) Then ParseItemsNode(i.ProjectItems) End If If (i.Name = "x.cs") Then keyword = keyword End If If (i.Name.IndexOf(keyword, StringComparison.InvariantCultureIgnoreCase) > -1) Then Dim found As ProjectItem = Nothing Dim index = i.Name.IndexOf(keyword, StringComparison.InvariantCultureIgnoreCase) Dim parentName = i.Name.Remove(index, keyword.Length - 1) Dim collection As IEnumerable If (TypeOf i.Collection.Parent() Is ProjectItem) Then collection = CType(i.Collection.Parent(), ProjectItem).Collection Else If (TypeOf i.Collection.Parent() Is Project) Then collection = CType(i.Collection.Parent(), Project).ProjectItems End If End If If collection IsNot Nothing Then For Each f As ProjectItem In collection If (f.Name = parentName) Then found = f Exit For End If Next End If If (found IsNot Nothing) Then 'AndAlso Not CType(found, Object).ReferenceEquals(found, i.Collection.Parent)) For Each prop As [Property] In i.Properties If prop.Name = "IsDependentFile" Then prop.IndexedValue(0) = True End If Next End If End If Next End Sub Private Sub ParseNamespaceElement(ByVal namespaceCodeElement As CodeElement, ByVal includeCreatedAuthorComment As Boolean, Optional ByVal commentUserName As String = Nothing, Optional ByVal commentDateStamp As String = Nothing, Optional ByVal moveInRegions As Boolean = True, Optional ByVal parseAsCodeElement As Boolean = False, Optional ByVal nestedTextSelection As EditPoint = Nothing) If (namespaceCodeElement.Kind = vsCMElement.vsCMElementImportStmt Or namespaceCodeElement.Kind = vsCMElement.vsCMElementIncludeStmt) Then Return End If Dim nestedObjectName As String Dim nestedObjectType As String If (nestedTextSelection IsNot Nothing And moveInRegions) Then Select Case namespaceCodeElement.Kind Case vsCMElement.vsCMElementClass Dim codeClass As CodeClass = namespaceCodeElement nestedObjectType = "Class " nestedObjectName = codeClass.Name Case vsCMElement.vsCMElementDelegate Dim codeDelegate As CodeDelegate = namespaceCodeElement nestedObjectType = "Delegate " nestedObjectName = codeDelegate.Name Case vsCMElement.vsCMElementEnum Dim codeEnum As CodeEnum = namespaceCodeElement nestedObjectType = "Enum " nestedObjectName = codeEnum.Name Case vsCMElement.vsCMElementStruct Dim codeStruct As CodeStruct = namespaceCodeElement nestedObjectType = "Struct " nestedObjectName = codeStruct.Name Case vsCMElement.vsCMElementInterface Dim codeInterface As CodeInterface = namespaceCodeElement nestedObjectType = "Interface " nestedObjectName = codeInterface.Name End Select If (nestedObjectName IsNot Nothing AndAlso nestedObjectType IsNot Nothing) Then 'Dim textSelection As TextSelection = DTE.ActiveDocument.Selection 'textSelection.MoveToPoint(namespaceCodeElement.GetEndPoint()) 'textSelection.Insert(vbCrLf + "#region " + nestedObjectName + " " + nestedObjectType + vbCrLf) nestedTextSelection.Insert(vbCrLf + "#region " + nestedObjectName + " " + nestedObjectType + vbCrLf) Dim ts As TextSelection = DTE.ActiveDocument.Selection Dim xmlComment As String = GetAndSetXmlDocComment("", namespaceCodeElement) ts.MoveToPoint(namespaceCodeElement.GetStartPoint()) ts.MoveToPoint(namespaceCodeElement.GetEndPoint(), True) Dim text As String = ts.Text ts.Delete() nestedTextSelection.Insert(text) GetAndSetXmlDocComment(xmlComment, namespaceCodeElement) 'nestedTextSelection = namespaceCodeElement.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint() End If End If If (namespaceCodeElement.Kind = vsCMElement.vsCMElementNamespace) Then ParseUsings(moveInRegions, namespaceCodeElement.Children) For Each codeElement As CodeElement In namespaceCodeElement.Members ParseCodeElement(codeElement, includeCreatedAuthorComment, commentUserName, commentDateStamp, moveInRegions, nestedTextSelection) Next Else If parseAsCodeElement Then ParseCodeElement(namespaceCodeElement, includeCreatedAuthorComment, commentUserName, commentDateStamp, moveInRegions, nestedTextSelection) End If End If If (nestedObjectName IsNot Nothing AndAlso nestedObjectType IsNot Nothing) Then Dim textSelection As TextSelection = DTE.ActiveDocument.Selection textSelection.MoveToPoint(namespaceCodeElement.GetEndPoint()) textSelection.Insert(vbCrLf + "#endregion " + nestedObjectType + " " + nestedObjectName + vbCrLf) nestedTextSelection.MoveToPoint(textSelection.AnchorPoint) End If End Sub Private Sub ParseCodeElement(ByVal codeElement As CodeElement, ByVal includeCreatedAuthorComment As Boolean, Optional ByVal commentUserName As String = Nothing, Optional ByVal commentDateStamp As String = Nothing, Optional ByVal moveInRegions As Boolean = True, Optional ByVal nestedTextSelection As EditPoint = Nothing) Select Case codeElement.Kind Case vsCMElement.vsCMElementNamespace ParseNamespaceElement(codeElement, includeCreatedAuthorComment, commentUserName, commentDateStamp, moveInRegions, False, nestedTextSelection) Case vsCMElement.vsCMElementClass, vsCMElement.vsCMElementInterface ParseClassElement(codeElement, codeElement, includeCreatedAuthorComment, commentUserName, commentDateStamp, moveInRegions, nestedTextSelection) Case vsCMElement.vsCMElementClass, vsCMElement.vsCMElementStruct ParseClassElement(codeElement, codeElement, includeCreatedAuthorComment, commentUserName, commentDateStamp, moveInRegions, nestedTextSelection) 'ParseNamespaceElement(codeElement, includeCreatedAuthorComment, commentUserName, commentDateStamp, moveInRegions) Case vsCMElement.vsCMElementEnum ParseEnumElement(codeElement, includeCreatedAuthorComment, commentUserName, commentDateStamp) Case vsCMElement.vsCMElementDelegate ParseDelegateElement(codeElement, includeCreatedAuthorComment, commentUserName, commentDateStamp) End Select End Sub Private Sub ParseDelegateElement(ByVal codeElement As CodeDelegate2, ByVal includeCreatedAuthorComment As Boolean, Optional ByVal commentUserName As String = Nothing, Optional ByVal commentDateStamp As String = Nothing) SetDocComment(codeElement, includeCreatedAuthorComment, commentUserName, commentDateStamp, "" & vbCrLf & "" & vbCrLf & "The " & codeElement.Name & " event handler" & vbCrLf & "" & vbCrLf & "") End Sub Private Sub ParseEnumElement(ByVal codeElement As CodeEnum, ByVal includeCreatedAuthorComment As Boolean, Optional ByVal commentUserName As String = Nothing, Optional ByVal commentDateStamp As String = Nothing) SetDocComment(codeElement, includeCreatedAuthorComment, commentUserName, commentDateStamp, "" & vbCrLf & "" & vbCrLf & "The " & codeElement.Name & " enum" & vbCrLf & "" & vbCrLf & "") For Each enumElement As CodeVariable2 In codeElement.Members SetDocComment(enumElement, includeCreatedAuthorComment, commentUserName, commentDateStamp, "" & vbCrLf & "" & vbCrLf & enumElement.Name & vbCrLf & "" & vbCrLf & "") Next End Sub Private Sub SetDocComment(ByVal codeElement As CodeElement, ByVal includeCreatedAuthorComment As Boolean, ByVal commentUserName As String, ByVal commentDateStamp As String, ByVal comment As String, Optional ByVal forceSetComment As Boolean = False) If Not comment.StartsWith("") Then comment = "" & vbCrLf & comment & vbCrLf & "" End If Select Case codeElement.Kind Case vsCMElement.vsCMElementVariable Dim codeVar As CodeVariable = codeElement codeVar.DocComment = "" SetDocComment(CType(codeElement, CodeVariable), includeCreatedAuthorComment, commentUserName, commentDateStamp, comment, forceSetComment) Case vsCMElement.vsCMElementEvent Dim codeEvent As CodeEvent = codeElement codeEvent.DocComment = "" SetDocComment(CType(codeElement, CodeEvent), includeCreatedAuthorComment, commentUserName, commentDateStamp, comment, forceSetComment) Case vsCMElement.vsCMElementClass SetDocComment(CType(codeElement, CodeClass), includeCreatedAuthorComment, commentUserName, commentDateStamp, comment, forceSetComment) Case vsCMElement.vsCMElementDelegate SetDocComment(CType(codeElement, CodeDelegate2), includeCreatedAuthorComment, commentUserName, commentDateStamp, comment, forceSetComment) Case vsCMElement.vsCMElementEnum SetDocComment(CType(codeElement, CodeEnum), includeCreatedAuthorComment, commentUserName, commentDateStamp, comment, forceSetComment) Case vsCMElement.vsCMElementFunction If (TypeOf codeElement Is CodeFunction) Then SetDocComment(CType(codeElement, CodeFunction), includeCreatedAuthorComment, commentUserName, commentDateStamp, comment, forceSetComment) Else SetDocComment(CType(codeElement, CodeFunction2), includeCreatedAuthorComment, commentUserName, commentDateStamp, comment, forceSetComment) End If Case vsCMElement.vsCMElementProperty If (TypeOf codeElement Is CodeProperty2) Then SetDocCommentCodeProperty2(CType(codeElement, CodeProperty2), includeCreatedAuthorComment, commentUserName, commentDateStamp, comment, forceSetComment) Else SetDocComment(CType(codeElement, CodeProperty), includeCreatedAuthorComment, commentUserName, commentDateStamp, comment, forceSetComment) End If End Select End Sub Private Sub SetDocComment(ByVal codeElement As CodeVariable, ByVal includeCreatedAuthorComment As Boolean, ByVal commentUserName As String, ByVal commentDateStamp As String, ByVal comment As String, Optional ByVal forceSetComment As Boolean = False) If forceSetComment Or codeElement.DocComment = "" Or codeElement.DocComment = "" & vbCrLf & "" Then Try codeElement.DocComment = comment Catch codeElement.StartPoint.CreateEditPoint().Insert(vbCrLf) codeElement.DocComment = comment End Try End If If includeCreatedAuthorComment AndAlso codeElement.DocComment.IndexOf(""), "") End If End Sub Private Sub SetDocComment(ByVal codeElement As CodeEvent, ByVal includeCreatedAuthorComment As Boolean, ByVal commentUserName As String, ByVal commentDateStamp As String, ByVal comment As String, Optional ByVal forceSetComment As Boolean = False) If forceSetComment Or codeElement.DocComment = "" Or codeElement.DocComment = "" & vbCrLf & "" Then Try codeElement.DocComment = comment Catch codeElement.StartPoint.CreateEditPoint().Insert(vbCrLf) codeElement.DocComment = comment End Try End If If includeCreatedAuthorComment AndAlso codeElement.DocComment.IndexOf(""), "") End If End Sub Private Sub SetDocComment(ByVal codeElement As CodeProperty, ByVal includeCreatedAuthorComment As Boolean, ByVal commentUserName As String, ByVal commentDateStamp As String, ByVal comment As String, Optional ByVal forceSetComment As Boolean = False) If forceSetComment Or codeElement.DocComment = "" Or codeElement.DocComment = "" & vbCrLf & "" Then Try codeElement.DocComment = comment Catch codeElement.StartPoint.CreateEditPoint().Insert(vbCrLf) codeElement.DocComment = comment End Try End If If includeCreatedAuthorComment AndAlso codeElement.DocComment.IndexOf(""), "") End If End Sub Private Sub SetDocCommentCodeProperty2(ByVal codeElement As CodeProperty2, ByVal includeCreatedAuthorComment As Boolean, ByVal commentUserName As String, ByVal commentDateStamp As String, ByVal comment As String, Optional ByVal forceSetComment As Boolean = False) If forceSetComment Or codeElement.DocComment = "" Or codeElement.DocComment = "" & vbCrLf & "" Then Try codeElement.DocComment = comment Catch codeElement.StartPoint.CreateEditPoint().Insert(vbCrLf) codeElement.DocComment = comment End Try End If If includeCreatedAuthorComment AndAlso codeElement.DocComment.IndexOf(""), "") End If End Sub Private Sub SetDocComment(ByVal codeElement As CodeFunction, ByVal includeCreatedAuthorComment As Boolean, ByVal commentUserName As String, ByVal commentDateStamp As String, ByVal comment As String, Optional ByVal forceSetComment As Boolean = False) If forceSetComment Or codeElement.DocComment = "" Or codeElement.DocComment = "" & vbCrLf & "" Then Try codeElement.DocComment = comment Catch codeElement.StartPoint.CreateEditPoint().Insert(vbCrLf) codeElement.DocComment = comment End Try End If If includeCreatedAuthorComment AndAlso codeElement.DocComment.IndexOf(""), "") End If End Sub Private Sub SetDocComment(ByVal codeElement As CodeFunction2, ByVal includeCreatedAuthorComment As Boolean, ByVal commentUserName As String, ByVal commentDateStamp As String, ByVal comment As String, Optional ByVal forceSetComment As Boolean = False) If forceSetComment Or codeElement.DocComment = "" Or codeElement.DocComment = "" & vbCrLf & "" Then Try codeElement.DocComment = comment Catch codeElement.StartPoint.CreateEditPoint().Insert(vbCrLf) codeElement.DocComment = comment End Try End If If includeCreatedAuthorComment AndAlso codeElement.DocComment.IndexOf(""), "") End If End Sub Private Sub SetDocComment(ByVal codeElement As CodeInterface, ByVal includeCreatedAuthorComment As Boolean, ByVal commentUserName As String, ByVal commentDateStamp As String, ByVal comment As String, Optional ByVal forceSetComment As Boolean = False) If forceSetComment Or codeElement.DocComment = "" Or codeElement.DocComment = "" & vbCrLf & "" Then Try codeElement.DocComment = comment Catch codeElement.StartPoint.CreateEditPoint().Insert(vbCrLf) codeElement.DocComment = comment End Try End If If includeCreatedAuthorComment AndAlso codeElement.DocComment.IndexOf(""), "") End If End Sub Private Sub SetDocComment(ByVal codeElement As CodeEnum, ByVal includeCreatedAuthorComment As Boolean, ByVal commentUserName As String, ByVal commentDateStamp As String, ByVal comment As String, Optional ByVal forceSetComment As Boolean = False) If forceSetComment Or codeElement.DocComment = "" Or codeElement.DocComment = "" & vbCrLf & "" Then Try codeElement.DocComment = comment Catch codeElement.StartPoint.CreateEditPoint().Insert(vbCrLf) codeElement.DocComment = comment End Try End If If includeCreatedAuthorComment AndAlso codeElement.DocComment.IndexOf(""), "") End If End Sub Private Sub SetDocComment(ByVal codeElement As CodeClass, ByVal includeCreatedAuthorComment As Boolean, ByVal commentUserName As String, ByVal commentDateStamp As String, ByVal comment As String, Optional ByVal forceSetComment As Boolean = False) If forceSetComment Or codeElement.DocComment = "" Or codeElement.DocComment = "" & vbCrLf & "" Then Try codeElement.DocComment = comment Catch codeElement.StartPoint.CreateEditPoint().Insert(vbCrLf) codeElement.DocComment = comment End Try End If If includeCreatedAuthorComment AndAlso codeElement.DocComment.IndexOf(""), "") End If End Sub Private Sub SetDocComment(ByVal codeElement As CodeDelegate2, ByVal includeCreatedAuthorComment As Boolean, ByVal commentUserName As String, ByVal commentDateStamp As String, ByVal comment As String, Optional ByVal forceSetComment As Boolean = False) If forceSetComment Or codeElement.DocComment = "" Or codeElement.DocComment = "" & vbCrLf & "" Then Try codeElement.DocComment = comment Catch codeElement.StartPoint.CreateEditPoint().Insert(vbCrLf) codeElement.DocComment = comment End Try End If If includeCreatedAuthorComment AndAlso codeElement.DocComment.IndexOf(""), "") End If End Sub Private Function GetDateStamp(ByVal commentDateStamp As String) As String If (commentDateStamp Is Nothing) Then Return DateTime.Now.ToString("R") End If Return commentDateStamp End Function Private Sub ParseClassElement(ByVal codeElement As CodeElement, ByVal codeElementType As CodeType, ByVal includeCreatedAuthorComment As Boolean, Optional ByVal commentUserName As String = Nothing, Optional ByVal commentDateStamp As String = Nothing, Optional ByVal moveInRegions As Boolean = True, Optional ByVal nestedTextSelection As EditPoint = Nothing) Dim projectItem As ProjectItem Dim fileCodeModel As FileCodeModel Dim regionFields As EditPoint Dim editPoint As EditPoint Dim commentStart As String 'ParseUsings(moveInRegions, codeElement.Children) If (codeElement.Kind = vsCMElement.vsCMElementClass Or codeElement.Kind = vsCMElement.vsCMElementStruct) Then Dim p As EditPoint = codeElementType.GetStartPoint(vsCMPart.vsCMPartHeader).CreateEditPoint() Dim s1 As String = p.GetText(-p.LineCharOffset) Dim s As String = p.GetText(p.LineLength - p.LineCharOffset) Dim i As Integer = s.IndexOf(":") If (i <> -1) Then Dim tabs = 0 While (s1.IndexOf(vbTab) <> -1) tabs += 1 s1 = s1.Remove(s1.IndexOf(vbTab), vbTab.Length) End While tabs += s1.Length / 4 p.MoveToLineAndOffset(p.Line, i + p.LineCharOffset) p.InsertNewLine() While (tabs > 0) p.Insert(vbTab) tabs = tabs - 1 End While End If End If editPoint = codeElementType.GetStartPoint(vsCMPart.vsCMPartHeader).CreateEditPoint() 'regionFields = nestedTextSelection 'If (regionFields Is Nothing) Then regionFields = codeElementType.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint() ' End If Dim textSelection As TextSelection '' Make doc comment start. commentStart = LineOrientedCommentStart() If (commentStart.Length = 2) Then commentStart = commentStart & commentStart.Chars(1) & " " ElseIf (commentStart.Length = 1) Then commentStart = commentStart & commentStart.Chars(0) & commentStart.Chars(0) & " " End If Try If (codeElement.Kind = vsCMElement.vsCMElementClass) Then Dim codeClass As CodeClass = codeElement SetDocComment(codeClass, includeCreatedAuthorComment, commentUserName, commentDateStamp, "" & vbCrLf & "" & vbCrLf & "The " & codeClass.Name & " class" & vbCrLf & "" & vbCrLf & "") End If If (codeElement.Kind = vsCMElement.vsCMElementInterface) Then Dim codeClass As CodeInterface = codeElement SetDocComment(codeClass, includeCreatedAuthorComment, commentUserName, commentDateStamp, "" & vbCrLf & "" & vbCrLf & "The " & codeClass.Name & " interface" & vbCrLf & "" & vbCrLf & "") End If Dim hasFields As Boolean = False For Each codeElement In codeElementType.Members If codeElement.Kind = vsCMElement.vsCMElementVariable Then hasFields = True Exit For End If Next MembersCache.Clear() If (hasFields) Then If moveInRegions Then BeginRegion(regionFields, "Fields") End If ParseCodeMembers(moveInRegions, commentStart, commentUserName, commentDateStamp, vsCMElement.vsCMElementVariable, regionFields, codeElementType, "Const", New MemberFilteringHandler(AddressOf MembersFilterVariableConsts), True, False, includeCreatedAuthorComment, False) ParseCodeMembers(moveInRegions, commentStart, commentUserName, commentDateStamp, vsCMElement.vsCMElementVariable, regionFields, codeElementType, "Static", New MemberFilteringHandler(AddressOf MembersFilterVariableStatic), True, False, includeCreatedAuthorComment, False) ParseCodeMembers(moveInRegions, commentStart, commentUserName, commentDateStamp, vsCMElement.vsCMElementVariable, regionFields, codeElementType, "", New MemberFilteringHandler(AddressOf MembersFilterVariablePrivate), True, False, includeCreatedAuthorComment, False) ParseCodeMembers(moveInRegions, commentStart, commentUserName, commentDateStamp, vsCMElement.vsCMElementVariable, regionFields, codeElementType, "", New MemberFilteringHandler(AddressOf MembersFilterVariableOthers), True, False, includeCreatedAuthorComment, False) If moveInRegions Then EndRegion(regionFields, "Fields") End If End If ParseCodeMembers(moveInRegions, commentStart, commentUserName, commentDateStamp, vsCMElement.vsCMElementFunction, regionFields, codeElementType, "Constructors", New MemberFilteringHandler(AddressOf MembersFilterConstructors), True, True, includeCreatedAuthorComment) ParseCodeMembers(moveInRegions, commentStart, commentUserName, commentDateStamp, vsCMElement.vsCMElementProperty, regionFields, codeElementType, "Util Properties", New MemberFilteringHandler(AddressOf PropertiesFilterUtil), True, True, includeCreatedAuthorComment) ParseCodeMembers(moveInRegions, commentStart, commentUserName, commentDateStamp, vsCMElement.vsCMElementProperty, regionFields, codeElementType, "Override Properties", New MemberFilteringHandler(AddressOf PropertiesFilterOverride), True, True, includeCreatedAuthorComment) ParseCodeMembers(moveInRegions, commentStart, commentUserName, commentDateStamp, vsCMElement.vsCMElementProperty, regionFields, codeElementType, "Properties", New MemberFilteringHandler(AddressOf PropertiesFilterPublic), True, True, includeCreatedAuthorComment) ParseCodeMembers(moveInRegions, commentStart, commentUserName, commentDateStamp, vsCMElement.vsCMElementEvent, regionFields, codeElementType, "Events", Nothing, True, True, includeCreatedAuthorComment) ParseCodeMembers(moveInRegions, commentStart, commentUserName, commentDateStamp, vsCMElement.vsCMElementFunction, regionFields, codeElementType, "Component Designer generated code", New MemberFilteringHandler(AddressOf MembersFilterMethodComponentDesignerGeneratedCode), True, True, includeCreatedAuthorComment) ParseCodeMembers(moveInRegions, commentStart, commentUserName, commentDateStamp, vsCMElement.vsCMElementFunction, regionFields, codeElementType, "Util Methods", IIf(moveInRegions, New MemberFilteringHandler(AddressOf MembersFilterMethodPrivate), New MemberFilteringHandler(AddressOf MembersFilterMethods)), True, True, includeCreatedAuthorComment, True, New MemberComentingHandler(AddressOf CommentsEventsMethods)) If (moveInRegions) Then ParseCodeMembers(moveInRegions, commentStart, commentUserName, commentDateStamp, vsCMElement.vsCMElementFunction, regionFields, codeElementType, "Events' Methods", New MemberFilteringHandler(AddressOf MembersFilterMethodControls), True, True, includeCreatedAuthorComment, True, New MemberComentingHandler(AddressOf CommentsEventsMethods)) ParseCodeMembers(moveInRegions, commentStart, commentUserName, commentDateStamp, vsCMElement.vsCMElementFunction, regionFields, codeElementType, "Override Methods", New MemberFilteringHandler(AddressOf MembersFilterMethodOverride), True, True, includeCreatedAuthorComment) ParseCodeMembers(moveInRegions, commentStart, commentUserName, commentDateStamp, vsCMElement.vsCMElementFunction, regionFields, codeElementType, "Business Methods", New MemberFilteringHandler(AddressOf MembersFilterMethodOthers), True, True, includeCreatedAuthorComment) End If For Each codeElement In codeElementType.Members If codeElement.Kind = vsCMElement.vsCMElementClass Or codeElement.Kind = vsCMElement.vsCMElementInterface Or codeElement.Kind = vsCMElement.vsCMElementStruct Or codeElement.Kind = vsCMElement.vsCMElementNamespace Or codeElement.Kind = vsCMElement.vsCMElementEnum Or codeElement.Kind = vsCMElement.vsCMElementDelegate Then ParseNamespaceElement(codeElement, includeCreatedAuthorComment, commentUserName, commentDateStamp, moveInRegions, codeElement.Kind <> vsCMElement.vsCMElementNamespace, regionFields) End If Next If moveInRegions Then Dim findWath As String = DTE.Find.FindWhat 'Application.DoEvents() DTE.Find.Action = vsFindAction.vsFindActionReplaceAll DTE.Find.FindWhat = "{\#region}{.*}{\n}{[ \t\n]*}{\#endregion}{.*}{\n}" DTE.Find.ReplaceWith = "" DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument DTE.Find.MatchCase = False DTE.Find.MatchWholeWord = False DTE.Find.MatchInHiddenText = True DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone DTE.Find.Execute() DTE.Find.Execute() DTE.Find.Action = vsFindAction.vsFindActionReplaceAll DTE.Find.FindWhat = "[ \t]*\n[ \t]*\n[ \t]*\n[ \t]*\n[ \t]*\n" DTE.Find.ReplaceWith = "\n" DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument DTE.Find.MatchCase = False DTE.Find.MatchWholeWord = False DTE.Find.MatchInHiddenText = True DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone DTE.Find.Execute() DTE.Find.Execute() DTE.Find.Execute() DTE.Find.Execute() DTE.Find.FindWhat = findWath End If Finally End Try End Sub Function GetAndSetXmlDocComment(ByVal docComment As String, ByVal codeElement As CodeElement) As String Dim xmlComment As String = docComment Select Case codeElement.Kind Case vsCMElement.vsCMElementClass Dim codeClass As CodeClass = codeElement xmlComment = codeClass.DocComment codeClass.DocComment = docComment Case vsCMElement.vsCMElementInterface Dim codeInterface As CodeInterface = codeElement xmlComment = codeInterface.DocComment codeInterface.DocComment = docComment Case vsCMElement.vsCMElementDelegate Dim codeDelegate As CodeDelegate = codeElement xmlComment = codeDelegate.DocComment codeDelegate.DocComment = docComment Case vsCMElement.vsCMElementEnum Dim codeEnum As CodeEnum = codeElement xmlComment = codeEnum.DocComment codeEnum.DocComment = docComment Case vsCMElement.vsCMElementStruct Dim codeStruct As CodeStruct = codeElement xmlComment = codeStruct.DocComment codeStruct.DocComment = docComment End Select Return xmlComment End Function Private Sub CommentsEventsMethods(ByVal codeElement As CodeElement, ByVal codeElementType As CodeType, ByRef defaultComment As String) If (codeElement.Name.StartsWith("On")) Then Dim sb As StringBuilder = New StringBuilder() sb.Append("Raises the ") sb.Append(codeElement.Name.Substring(2)) sb.Append(" event") 'sb.Append(vbCrLf) defaultComment = sb.ToString() Return End If Dim indexOfUnderScore = codeElement.Name.LastIndexOf("_") If (indexOfUnderScore > 0) Then Dim sb As StringBuilder = New StringBuilder() sb.Append("Handles the ") Dim handlerName As String = codeElement.Name.Substring(0, indexOfUnderScore) sb.Append(handlerName) sb.Append("'") If (Not handlerName.EndsWith("s", StringComparison.OrdinalIgnoreCase)) Then sb.Append("s") End If sb.Append(" ") sb.Append(codeElement.Name.Substring(indexOfUnderScore + 1)) sb.Append(" event") 'sb.Append(vbCrLf) defaultComment = sb.ToString() End If End Sub Private Sub BeginRegion(ByVal regionFields As EditPoint, ByVal regionName As String) regionFields.Insert(vbCrLf & "#region " & regionName & vbCrLf & vbCrLf) End Sub Private Sub EndRegion(ByVal regionFields As EditPoint, ByVal regionName As String) regionFields.Insert(vbCrLf + "#endregion " + regionName + vbCrLf + vbCrLf) End Sub Private Function MembersFilterConstructors(ByVal codeElement As CodeElement, ByVal codeElementType As CodeType) As Boolean If codeElement.Kind = vsCMElement.vsCMElementFunction Then Dim code As CodeFunction = codeElement Return code.FunctionKind = vsCMFunction.vsCMFunctionConstructor Or code.FunctionKind = vsCMFunction.vsCMFunctionDestructor End If End Function Private Function MembersFilterVariableConsts(ByVal codeElement As CodeElement, ByVal codeElementType As CodeType) As Boolean If codeElement.Kind = vsCMElement.vsCMElementVariable Then Dim code As CodeVariable = codeElement Return code.IsConstant End If Return False End Function Private Function MembersFilterVariableStatic(ByVal codeElement As CodeElement, ByVal codeElementType As CodeType) As Boolean If codeElement.Kind = vsCMElement.vsCMElementVariable Then Dim code As CodeVariable = codeElement Return code.IsShared AndAlso Not code.IsConstant End If Return False End Function Private Function MembersFilterVariablePrivate(ByVal codeElement As CodeElement, ByVal codeElementType As CodeType) As Boolean If codeElement.Kind = vsCMElement.vsCMElementVariable Then Dim code As CodeVariable = codeElement Return (code.Access = vsCMAccess.vsCMAccessPrivate Or code.Access = vsCMAccess.vsCMAccessDefault) AndAlso Not code.IsConstant AndAlso Not code.IsShared End If Return False End Function Private Function MembersFilterVariableOthers(ByVal codeElement As CodeElement, ByVal codeElementType As CodeType) As Boolean If codeElement.Kind = vsCMElement.vsCMElementVariable Then Dim code As CodeVariable = codeElement Return Not code.Access = vsCMAccess.vsCMAccessPrivate AndAlso Not code.Access = vsCMAccess.vsCMAccessDefault AndAlso Not code.IsConstant AndAlso Not code.IsShared End If Return False End Function Private Function MembersFilterMethodOverride(ByVal codeElement As CodeElement, ByVal codeElementType As CodeType) As Boolean If codeElement.Kind = vsCMElement.vsCMElementFunction Then Dim code As CodeFunction = codeElement If (TypeOf codeElement Is CodeFunction2) Then Dim code2 As CodeFunction2 = codeElement Return Not code.FunctionKind = vsCMFunction.vsCMFunctionConstructor AndAlso Not code.FunctionKind = vsCMFunction.vsCMFunctionDestructor _ AndAlso (code2.OverrideKind AndAlso vsCMOverrideKind.vsCMOverrideKindOverride = vsCMOverrideKind.vsCMOverrideKindOverride) _ AndAlso Not MembersFilterMethodComponentDesignerGeneratedCode(codeElement, codeElementType) _ AndAlso Not MembersFilterMethodControls(codeElement, codeElementType) Else Return Not code.FunctionKind = vsCMFunction.vsCMFunctionConstructor AndAlso Not code.FunctionKind = vsCMFunction.vsCMFunctionDestructor _ AndAlso Not FindBaseMemberCached(codeElement, codeElementType) Is Nothing _ AndAlso Not MembersFilterMethodComponentDesignerGeneratedCode(codeElement, codeElementType) End If End If Return False End Function Private Function MembersFilterMethodControls(ByVal codeElement As CodeElement, ByVal codeElementType As CodeType) As Boolean If codeElement.Kind = vsCMElement.vsCMElementFunction Then Dim code As CodeFunction = codeElement Return Not code.FunctionKind = vsCMFunction.vsCMFunctionConstructor AndAlso Not code.FunctionKind = vsCMFunction.vsCMFunctionDestructor _ AndAlso code.Name.Contains("_") _ AndAlso Not MembersFilterMethodComponentDesignerGeneratedCode(codeElement, codeElementType) End If Return False End Function Private Function IsMemberStatic(ByVal member As CodeElement) As Boolean Dim c As CodeProperty If member.Kind = vsCMElement.vsCMElementFunction Then Return member.IsShared ElseIf member.Kind = vsCMElement.vsCMElementProperty Then If Not member.Getter Is Nothing Then Return member.Getter.IsShared ElseIf Not member.Setter Is Nothing Then Return member.Setter.IsShared Else Return False End If End If End Function Dim MembersCache As Hashtable = New Hashtable() Private Function FindBaseMemberCached(ByVal descendentMember As CodeElement, _ ByVal typeElement As CodeElement) As CodeElement Throw New Exception("brr") If MembersCache.ContainsKey(descendentMember) Then Return MembersCache(descendentMember) Else Dim el = FindBaseMember(descendentMember, typeElement) MembersCache.Add(descendentMember, el) End If End Function Private Function FindBaseMember(ByVal descendentMember As CodeElement, _ ByVal typeElement As CodeElement) As CodeElement Throw New Exception("brr") If descendentMember.Parent.FullName <> typeElement.FullName Then For Each member As CodeElement In typeElement.Members If IsMemberStatic(member) = False _ AndAlso member.Name = descendentMember.Name _ AndAlso member.Kind = descendentMember.Kind _ AndAlso member.Type.AsString = _ descendentMember.Type.AsString Then If member.Kind = vsCMElement.vsCMElementFunction Then ' Compare method parameters If member.Parameters.Count <> _ descendentMember.Parameters.Count Then GoTo MemberEnd End If For i As Integer = 1 To member.Parameters.Count Dim paramX As CodeParameter = _ member.Parameters.Item(i) Dim paramY As CodeParameter = _ descendentMember.Parameters.Item(i) If paramX.Type.AsString <> paramY.Type.AsString Then ' Different overloads: skip GoTo MemberEnd End If Next End If ' Matching base member found Return member End If MemberEnd: Next End If ' Matching base member not found, keep looking Dim baseTypeList As ArrayList = New ArrayList() For Each baseType As CodeElement In typeElement.Bases baseTypeList.Add(baseType) Next If Not TypeOf (typeElement) Is CodeInterface Then For Each baseInterface As CodeElement In _ typeElement.ImplementedInterfaces baseTypeList.Add(baseInterface) Next End If For Each baseType As CodeElement In baseTypeList Dim baseMember As CodeElement = _ FindBaseMember(descendentMember, baseType) If Not baseMember Is Nothing Then Return baseMember End If Next ' No base member found Return Nothing End Function Private Function PropertiesFilterUtil(ByVal codeElement As CodeElement, ByVal codeElementType As CodeType) As Boolean If codeElement.Kind = vsCMElement.vsCMElementProperty Then Dim code As CodeProperty = codeElement Return (code.Access = vsCMAccess.vsCMAccessDefault Or code.Access = vsCMAccess.vsCMAccessPrivate Or code.Access = vsCMAccess.vsCMAccessAssemblyOrFamily Or code.Access = vsCMAccess.vsCMAccessProject) AndAlso Not PropertiesFilterOverride(codeElement, codeElementType) End If Return False End Function Private Function PropertiesFilterOverride(ByVal codeElement As CodeElement, ByVal codeElementType As CodeType) As Boolean If codeElement.Kind = vsCMElement.vsCMElementProperty Then Dim code As CodeProperty = codeElement If (TypeOf codeElement Is CodeProperty2) Then Dim code2 As CodeProperty2 = codeElement Return Not code.FunctionKind = vsCMFunction.vsCMFunctionConstructor AndAlso Not code.FunctionKind = vsCMFunction.vsCMFunctionDestructor _ AndAlso (code2.OverrideKind AndAlso vsCMOverrideKind.vsCMOverrideKindOverride = vsCMOverrideKind.vsCMOverrideKindOverride) _ AndAlso Not MembersFilterMethodComponentDesignerGeneratedCode(codeElement, codeElementType) End If End If Return False End Function Private Function PropertiesFilterPublic(ByVal codeElement As CodeElement, ByVal codeElementType As CodeType) As Boolean If codeElement.Kind = vsCMElement.vsCMElementProperty Then Dim code As CodeProperty = codeElement Return Not PropertiesFilterUtil(codeElement, codeElementType) AndAlso Not PropertiesFilterOverride(codeElement, codeElementType) End If Return False End Function Private Function MembersFilterMethodComponentDesignerGeneratedCode(ByVal codeElement As CodeElement, ByVal codeElementType As CodeType) As Boolean If codeElement.Kind = vsCMElement.vsCMElementFunction Then Dim code As CodeFunction = codeElement Return (code.Name = "InitializeComponent") _ AndAlso Not code.FunctionKind = vsCMFunction.vsCMFunctionConstructor AndAlso Not code.FunctionKind = vsCMFunction.vsCMFunctionDestructor End If Return False End Function Private Function MembersFilterMethodPrivate(ByVal codeElement As CodeElement, ByVal codeElementType As CodeType) As Boolean If codeElement.Kind = vsCMElement.vsCMElementFunction Then Dim code As CodeFunction = codeElement Return (code.Access = vsCMAccess.vsCMAccessDefault Or code.Access = vsCMAccess.vsCMAccessPrivate) _ AndAlso Not MembersFilterMethodOverride(codeElement, codeElementType) AndAlso Not code.FunctionKind = vsCMFunction.vsCMFunctionConstructor AndAlso Not code.FunctionKind = vsCMFunction.vsCMFunctionDestructor AndAlso Not MembersFilterMethodComponentDesignerGeneratedCode(codeElement, codeElementType) _ AndAlso Not MembersFilterMethodControls(codeElement, codeElementType) End If Return False End Function Private Function MembersFilterMethodOthers(ByVal codeElement As CodeElement, ByVal codeElementType As CodeType) As Boolean If codeElement.Kind = vsCMElement.vsCMElementFunction Then Dim code As CodeFunction = codeElement Return code.Access <> vsCMAccess.vsCMAccessDefault AndAlso code.Access <> vsCMAccess.vsCMAccessPrivate _ AndAlso Not code.FunctionKind = vsCMFunction.vsCMFunctionConstructor AndAlso Not code.FunctionKind = vsCMFunction.vsCMFunctionDestructor _ AndAlso Not MembersFilterMethodOverride(codeElement, codeElementType) _ AndAlso Not MembersFilterMethodComponentDesignerGeneratedCode(codeElement, codeElementType) _ AndAlso Not MembersFilterMethodControls(codeElement, codeElementType) End If Return False End Function Private Function MembersFilterMethods(ByVal codeElement As CodeElement, ByVal codeElementType As CodeType) As Boolean If codeElement.Kind = vsCMElement.vsCMElementFunction Then Return True 'Dim code As CodeFunction = codeElement 'Return code.Kind = vsCMElement.vsCMElementFunction <> vsCMAccess.vsCMAccessDefault AndAlso code.Access <> vsCMAccess.vsCMAccessPrivate _ ' AndAlso Not MembersFilterMethodOverride(codeElement, codeElementType) AndAlso Not code.FunctionKind = vsCMFunction.vsCMFunctionConstructor AndAlso Not code.FunctionKind = vsCMFunction.vsCMFunctionDestructor End If Return False End Function Delegate Function MemberFilteringHandler(ByVal codeElement As CodeElement, ByVal codeElementType As CodeType) As Boolean Delegate Sub MemberComentingHandler(ByVal codeElement As CodeElement, ByVal codeElementType As CodeType, ByRef defaultComment As String) Private Sub ParseCodeMembers(ByVal moveInRegions As Boolean, ByVal commentStart As String, ByVal commentUserName As String, ByVal commentDateStamp As String, ByVal memberType As vsCMElement, ByVal regionFields As EditPoint, ByVal codeElementType As CodeType, ByVal regionName As String, Optional ByRef onFiltering As MemberFilteringHandler = Nothing, Optional ByVal includeRegionOnlyIfExistMembers As Boolean = False, Optional ByVal insertEnterAfter As Boolean = True, Optional ByVal addCreatedByCommentIfNotExists As Boolean = True, Optional ByVal addCommentIfNotExists As Boolean = True, Optional ByRef onCommenting As MemberComentingHandler = Nothing) Dim regionInserted As Boolean = False If (regionName <> "" AndAlso includeRegionOnlyIfExistMembers = False AndAlso moveInRegions) Then regionInserted = True BeginRegion(regionFields, regionName) End If Dim codeElement As CodeElement Dim textSelection As TextSelection 'if not moveIn regions do not comment If (Not moveInRegions) Then commentStart = "" End If For Each codeElement In codeElementType.Members 'If (codeElement.Kind = vsCMElement.vsCMElementClass Or codeElement.Kind = vsCMElement.vsCMElementNamespace Or codeElement.Kind = vsCMElement.vsCMElementInterface Or codeElement.Kind = vsCMElement.vsCMElementEnum Or codeElement.Kind = vsCMElement.vsCMElementDelegate) Then ' ParseNamespaceElement(codeElement, addCommentIfNotExists, commentUserName, commentDateStamp, moveInRegions) 'End If ' Try Dim parse As Boolean = codeElement.Kind = memberType If Not onFiltering Is Nothing Then parse = onFiltering(codeElement, codeElementType) End If If (parse) Then Dim doAddCreatedByComment As Boolean = False 'if includeRegionOnlyIfExistMembers AndAlso exist members, then start the region If (regionName <> "" AndAlso includeRegionOnlyIfExistMembers = True AndAlso regionInserted = False AndAlso moveInRegions) Then regionInserted = True BeginRegion(regionFields, regionName) End If textSelection = DTE.ActiveDocument.Selection Dim comment As String = codeElement.DocComment If comment <> "" + vbCrLf + "" Then comment = comment.Substring(7, comment.Length - 7 - 6) Else : comment = "" End If Dim linesCount As Integer = 0 If moveInRegions Then textSelection.MoveToPoint(codeElement.GetStartPoint()) If comment <> "" Then linesCount = comment.Split(vbCr).Length - 1 textSelection.MoveToLineAndOffset(textSelection.ActivePoint.Line - linesCount, 1) End If End If Dim forceSetComment = False If comment = "" Then If addCommentIfNotExists Then Dim sbc As StringBuilder = New StringBuilder() sbc.Append(commentStart) sbc.Append("") 'sbc.Append(vbCrLf) Dim defaultComment As String = String.Empty If codeElement.Kind = vsCMElement.vsCMElementFunction Then Dim codeFunction As CodeFunction = codeElement If codeFunction.FunctionKind = vsCMFunction.vsCMFunctionConstructor Then If (codeFunction.IsShared) Then defaultComment += "Static constructor of " + codeElement.Name Else defaultComment += "Creates a new instance of " + codeElement.Name End If End If ElseIf codeElement.Kind = vsCMElement.vsCMElementProperty Then Dim codeProperty As CodeProperty = codeElement If Not codeProperty.Getter Is Nothing AndAlso Not codeProperty.Setter Is Nothing AndAlso codeProperty.Setter.Access = codeProperty.Getter.Access Then defaultComment += "Gets or sets the " + System.Web.HttpUtility.HtmlAttributeEncode(codeElement.Name) ElseIf Not codeProperty.Getter Is Nothing Then defaultComment += "Gets the " + System.Web.HttpUtility.HtmlAttributeEncode(codeElement.Name) ElseIf Not codeProperty.Setter Is Nothing Then defaultComment += "Sets the " + System.Web.HttpUtility.HtmlAttributeEncode(codeElement.Name) Else 'defaultComment += vbCrLf End If End If If Not onCommenting Is Nothing Then onCommenting(codeElement, codeElementType, defaultComment) End If If (String.IsNullOrEmpty(defaultComment)) Then 'defaultComment += " " + vbCrLf End If sbc.Append(commentStart) sbc.Append(defaultComment) sbc.Append(commentStart) sbc.Append("") sbc.Append(vbCrLf) If codeElement.Kind = vsCMElement.vsCMElementFunction Then Dim codeFunction As CodeFunction = codeElement Dim codeParameter As CodeParameter For Each codeParameter In codeFunction.Parameters sbc.Append(commentStart) sbc.Append("") sbc.Append(vbCrLf) Next If codeFunction.Type.TypeKind <> vsCMTypeRef.vsCMTypeRefVoid Then sbc.Append(commentStart) sbc.Append("") sbc.Append(vbCrLf) End If End If If addCreatedByCommentIfNotExists Then sbc.Append(commentStart) sbc.Append("") sbc.Append(vbCrLf) End If comment = sbc.ToString() End If Else If moveInRegions Then If addCreatedByCommentIfNotExists AndAlso Not comment Is Nothing AndAlso comment.IndexOf("" & vbCrLf End If Dim firstIndex = comment.IndexOf("") Dim lastIndex = comment.IndexOf("") If Not comment Is Nothing AndAlso firstIndex <> -1 AndAlso lastIndex <> -1 AndAlso firstIndex < lastIndex Then Dim str = comment.Substring(firstIndex + 9, lastIndex - firstIndex - 9) Dim check = 0 If str.StartsWith(vbCrLf) Then str = str.Substring(vbCrLf.Length).TrimStart() check = 1 End If If str.EndsWith(vbCrLf) Then str = str.Substring(0, str.Length - vbCrLf.Length).TrimEnd() check += 2 End If If check <> 0 AndAlso str.IndexOf(vbCrLf) = -1 Then forceSetComment = True comment = comment.Remove(firstIndex + 9, lastIndex - firstIndex - 9).Insert(firstIndex + 9, str) ElseIf (check = 0 Or check <> 3) AndAlso str.IndexOf(vbCrLf) <> -1 AndAlso str.Length > 0 Then forceSetComment = True comment = comment.Remove(firstIndex + 9, lastIndex - firstIndex - 9).Insert(firstIndex + 9, vbCrLf + str + vbCrLf) End If End If End If End If If moveInRegions Then Dim str As String = "" 'textSelection.MoveToPoint(codeElement.GetStartPoint(vsCMPart.vsCMPartWholeWithAttributes), True) 'str = textSelection.Text 'If (doAddCreatedByComment) Then ' str += vbCrLf & commentStart & "" 'End If 'textSelection.MoveToPoint(codeElement.GetStartPoint(vsCMPart.vsCMPartWholeWithAttributes), False) textSelection.MoveToPoint(codeElement.GetEndPoint(vsCMPart.vsCMPartWholeWithAttributes), True) textSelection.LineDown(True) textSelection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn, True) textSelection.MoveToPoint(codeElement.GetEndPoint(vsCMPart.vsCMPartWholeWithAttributes), True) textSelection.LineDown(True) textSelection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn, True) If Not comment Is Nothing Then str = comment & str & textSelection.Text Else str += textSelection.Text If addCreatedByCommentIfNotExists Then Dim lines As String() = str.Split(vbCr) Dim commented As Boolean = False Dim builder As StringBuilder = New StringBuilder() For i As Integer = 0 To lines.Length - 1 If i < linesCount AndAlso lines(i).IndexOf(" -1 Then commented = True Exit For End If Dim line As String = lines(i).Replace(vbLf, vbCrLf) builder.Append(line) If i = linesCount - 1 AndAlso Not commented Then builder.Append(vbCrLf & commentStart & "") End If Next If Not commented Then str = builder.ToString() End If End If End If textSelection.Text = "" regionFields.Insert(str) If (insertEnterAfter) Then regionFields.Insert(vbCrLf) End If Else If (Not comment Is Nothing) Then 'comment = comment.Replace(" ", "") comment = comment.Replace(vbCrLf, " " & vbCrLf) comment = comment.Replace("> ", ">") End If If ((codeElement.Kind = vsCMElement.vsCMElementVariable Or codeElement.Kind = vsCMElement.vsCMElementEvent) AndAlso comment = "") Then Continue For End If If (Not onCommenting Is Nothing) Then Dim startSummary As Integer = comment.IndexOf("") Dim endSummary As Integer = comment.IndexOf("") If (startSummary > -1 And startSummary < endSummary) Then startSummary += 9 Dim innerComment = comment.Substring(startSummary, endSummary - startSummary).Trim() If (innerComment.Length = 0) Then Dim newComment As String = String.Empty onCommenting(codeElement, codeElementType, newComment) comment = comment.Remove(startSummary, endSummary - startSummary).Insert(startSummary, vbCrLf & commentStart & newComment & vbCrLf & commentStart) SetDocComment(codeElement, addCreatedByCommentIfNotExists, commentUserName, commentDateStamp, comment, True) Continue For End If End If End If SetDocComment(codeElement, addCreatedByCommentIfNotExists, commentUserName, commentDateStamp, comment, forceSetComment) End If End If ' Catch ex As Exception ' End Try Next If (regionName <> "" AndAlso regionInserted AndAlso moveInRegions) Then EndRegion(regionFields, regionName) End If End Sub