Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code generation macro

Status
Not open for further replies.

chrissie1

Programmer
Aug 12, 2002
4,517
BE
I thought I should share this for you kids.

I start of with this

Code:
[Blue]Public[/Blue] [Blue]Class[/Blue] Event_Type
    [Blue]Private[/Blue] _Id [Blue]As[/Blue] [Blue]Integer[/Blue]
    [Blue]Private[/Blue] _Type [Blue]As[/Blue] [Blue]Integer[/Blue]
    [Blue]Private[/Blue] _R [Blue]As[/Blue] [Blue]Integer[/Blue]
    [Blue]Private[/Blue] _G [Blue]As[/Blue] [Blue]Integer[/Blue]
    [Blue]Private[/Blue] _B [Blue]As[/Blue] [Blue]Integer[/Blue]
[Blue]End[/Blue] [Blue]Class[/Blue]

and then I select the private members and run the macro which gives me this.

Code:
[Blue]Public[/Blue] [Blue]Class[/Blue] Event_Type
    
#[Blue]Region[/Blue] [Red]" Private members "[/Red]
		[Green]''' <summary>[/Green]
		[Green]''' A local variable called _Id of type Integer[/Green]
		[Green]''' </summary>[/Green]
		[Green]''' <remarks>Has Property Id</remarks>[/Green]
		[Blue]Private[/Blue] _Id [Blue]As[/Blue] [Blue]Integer[/Blue]
		[Green]''' <summary>[/Green]
		[Green]''' A local variable called _Type of type Integer[/Green]
		[Green]''' </summary>[/Green]
		[Green]''' <remarks>Has Property Type</remarks>[/Green]
		[Blue]Private[/Blue] _Type [Blue]As[/Blue] [Blue]Integer[/Blue]
		[Green]''' <summary>[/Green]
		[Green]''' A local variable called _R of type Integer[/Green]
		[Green]''' </summary>[/Green]
		[Green]''' <remarks>Has Property R</remarks>[/Green]
		[Blue]Private[/Blue] _R [Blue]As[/Blue] [Blue]Integer[/Blue]
		[Green]''' <summary>[/Green]
		[Green]''' A local variable called _G of type Integer[/Green]
		[Green]''' </summary>[/Green]
		[Green]''' <remarks>Has Property G</remarks>[/Green]
		[Blue]Private[/Blue] _G [Blue]As[/Blue] [Blue]Integer[/Blue]
		[Green]''' <summary>[/Green]
		[Green]''' A local variable called _B of type Integer[/Green]
		[Green]''' </summary>[/Green]
		[Green]''' <remarks>Has Property B</remarks>[/Green]
		[Blue]Private[/Blue] _B [Blue]As[/Blue] [Blue]Integer[/Blue]
#[Blue]End[/Blue] [Blue]Region[/Blue]

#[Blue]Region[/Blue] [Red]" Constructors "[/Red]
		[Green]''' <summary>[/Green]
		[Green]''' Default empty constructor[/Green]
		[Green]''' </summary>[/Green]
		[Green]''' <remarks></remarks>[/Green]
		[Blue]Public[/Blue] [Blue]Sub[/Blue] [Blue]New[/Blue]()
			[Green]'Implement default constructor[/Green]
		[Blue]End[/Blue] [Blue]Sub[/Blue]

		[Green]''' <summary>[/Green]
		[Green]''' Constructor with all the fields[/Green]
		[Green]''' </summary>[/Green]
		[Green]''' <param name=[Red]"Id"[/Red]>DataType = Integer</param>[/Green]
		[Green]''' <param name=[Red]"Type"[/Red]>DataType = Integer</param>[/Green]
		[Green]''' <param name=[Red]"R"[/Red]>DataType = Integer</param>[/Green]
		[Green]''' <param name=[Red]"G"[/Red]>DataType = Integer</param>[/Green]
		[Green]''' <param name=[Red]"B"[/Red]>DataType = Integer</param>[/Green]
		[Green]''' <remarks></remarks>[/Green]
		[Blue]Public[/Blue] [Blue]Sub[/Blue] [Blue]New[/Blue]([Blue]ByVal[/Blue] Id [Blue]As[/Blue] [Blue]Integer[/Blue], [Blue]ByVal[/Blue] Type [Blue]As[/Blue] [Blue]Integer[/Blue], [Blue]ByVal[/Blue] R [Blue]As[/Blue] [Blue]Integer[/Blue], [Blue]ByVal[/Blue] G [Blue]As[/Blue] [Blue]Integer[/Blue], [Blue]ByVal[/Blue] B [Blue]As[/Blue] [Blue]Integer[/Blue])
			[Blue]Me[/Blue].Id = _Id
			[Blue]Me[/Blue].Type = _Type
			[Blue]Me[/Blue].R = _R
			[Blue]Me[/Blue].G = _G
			[Blue]Me[/Blue].B = _B
		[Blue]End[/Blue] [Blue]Sub[/Blue]
#[Blue]End[/Blue] [Blue]Region[/Blue]

#[Blue]Region[/Blue] [Red]" Public properties "[/Red]
		[Green]''' <summary>[/Green]
		[Green]''' This is the Id property.[/Green]
		[Green]''' </summary>[/Green]
		[Green]''' <value>Integer</value>[/Green]
		[Green]''' <returns>Integer</returns>[/Green]
		[Green]''' <remarks></remarks>[/Green]
		[Blue]Public[/Blue] Property Id [Blue]As[/Blue] [Blue]Integer[/Blue]
		    Get
		        [Blue]Return[/Blue] _Id
		    [Blue]End[/Blue] Get
		    Set([Blue]ByVal[/Blue] Value [Blue]As[/Blue] [Blue]Integer[/Blue])
		        _Id = Value
		    [Blue]End[/Blue] Set
		[Blue]End[/Blue] Property

		[Green]''' <summary>[/Green]
		[Green]''' This is the Type property.[/Green]
		[Green]''' </summary>[/Green]
		[Green]''' <value>Integer</value>[/Green]
		[Green]''' <returns>Integer</returns>[/Green]
		[Green]''' <remarks></remarks>[/Green]
		[Blue]Public[/Blue] Property Type [Blue]As[/Blue] [Blue]Integer[/Blue]
		    Get
		        [Blue]Return[/Blue] _Type
		    [Blue]End[/Blue] Get
		    Set([Blue]ByVal[/Blue] Value [Blue]As[/Blue] [Blue]Integer[/Blue])
		        _Type = Value
		    [Blue]End[/Blue] Set
		[Blue]End[/Blue] Property

		[Green]''' <summary>[/Green]
		[Green]''' This is the R property.[/Green]
		[Green]''' </summary>[/Green]
		[Green]''' <value>Integer</value>[/Green]
		[Green]''' <returns>Integer</returns>[/Green]
		[Green]''' <remarks></remarks>[/Green]
		[Blue]Public[/Blue] Property R [Blue]As[/Blue] [Blue]Integer[/Blue]
		    Get
		        [Blue]Return[/Blue] _R
		    [Blue]End[/Blue] Get
		    Set([Blue]ByVal[/Blue] Value [Blue]As[/Blue] [Blue]Integer[/Blue])
		        _R = Value
		    [Blue]End[/Blue] Set
		[Blue]End[/Blue] Property

		[Green]''' <summary>[/Green]
		[Green]''' This is the G property.[/Green]
		[Green]''' </summary>[/Green]
		[Green]''' <value>Integer</value>[/Green]
		[Green]''' <returns>Integer</returns>[/Green]
		[Green]''' <remarks></remarks>[/Green]
		[Blue]Public[/Blue] Property G [Blue]As[/Blue] [Blue]Integer[/Blue]
		    Get
		        [Blue]Return[/Blue] _G
		    [Blue]End[/Blue] Get
		    Set([Blue]ByVal[/Blue] Value [Blue]As[/Blue] [Blue]Integer[/Blue])
		        _G = Value
		    [Blue]End[/Blue] Set
		[Blue]End[/Blue] Property

		[Green]''' <summary>[/Green]
		[Green]''' This is the B property.[/Green]
		[Green]''' </summary>[/Green]
		[Green]''' <value>Integer</value>[/Green]
		[Green]''' <returns>Integer</returns>[/Green]
		[Green]''' <remarks></remarks>[/Green]
		[Blue]Public[/Blue] Property B [Blue]As[/Blue] [Blue]Integer[/Blue]
		    Get
		        [Blue]Return[/Blue] _B
		    [Blue]End[/Blue] Get
		    Set([Blue]ByVal[/Blue] Value [Blue]As[/Blue] [Blue]Integer[/Blue])
		        _B = Value
		    [Blue]End[/Blue] Set
		[Blue]End[/Blue] Property
#[Blue]End[/Blue] [Blue]Region[/Blue]

#[Blue]Region[/Blue] [Red]" Overrides ToString "[/Red]
		[Green]''' <summary>[/Green]
		[Green]''' Overridden ToString method for this class[/Green]
		[Green]''' </summary>[/Green]
		[Green]''' <returns>String</returns>[/Green]
		[Green]''' <remarks>The String value of this class represented by the ToStrings of all it's private members</remarks>[/Green]
		[Blue]Public[/Blue] [Blue]Overrides[/Blue] [Blue]Function[/Blue] ToString() [Blue]As[/Blue] [Blue]String[/Blue]
			[Blue]Dim[/Blue] ReturnString [Blue]As[/Blue] [Blue]New[/Blue] System.Text.StringBuilder()
			ReturnString.Append([Red]"[Id: "[/Red] & _Id.ToString() & [Red]"]"[/Red])
			ReturnString.Append([Red]" - [Type: "[/Red] & _Type.ToString() & [Red]"]"[/Red])
			ReturnString.Append([Red]" - [R: "[/Red] & _R.ToString() & [Red]"]"[/Red])
			ReturnString.Append([Red]" - [G: "[/Red] & _G.ToString() & [Red]"]"[/Red])
			ReturnString.Append([Red]" - [B: "[/Red] & _B.ToString() & [Red]"]"[/Red])
			[Blue]Return[/Blue] ReturnString.ToString()
		[Blue]End[/Blue] [Blue]Function[/Blue]
#[Blue]End[/Blue] [Blue]Region[/Blue]


[Blue]End[/Blue] [Blue]Class[/Blue]



Christiaan Baes
Belgium

"My new site" - Me
 
And now the macro

Code:
[Blue]Sub[/Blue] Construct_Class()
        DTE.UndoContext.Open([Red]"ToString"[/Red])
        [Blue]Dim[/Blue] _TextSelection [Blue]As[/Blue] TextSelection = [Blue]Nothing[/Blue]
        [Blue]Dim[/Blue] _OriginalCode [Blue]As[/Blue] [Blue]String[/Blue] = [Red]""[/Red]
        [Blue]Dim[/Blue] _Line [Blue]As[/Blue] [Blue]String[/Blue] = [Red]""[/Red]
        [Blue]Dim[/Blue] _Lines() [Blue]As[/Blue] [Blue]String[/Blue]
        [Blue]Dim[/Blue] _VariableName
        [Blue]Dim[/Blue] _PublicName [Blue]As[/Blue] [Blue]String[/Blue] = [Red]""[/Red]
        [Blue]Dim[/Blue] _DataType [Blue]As[/Blue] [Blue]String[/Blue] = [Red]""[/Red]
        [Blue]Dim[/Blue] _Declarations [Blue]As[/Blue] [Blue]String[/Blue] = [Red]""[/Red]
        [Blue]Dim[/Blue] _DocTags [Blue]As[/Blue] [Blue]String[/Blue] = [Red]""[/Red]
        [Blue]Dim[/Blue] _Fills [Blue]As[/Blue] [Blue]String[/Blue] = [Red]""[/Red]
        [Blue]Dim[/Blue] _Procedure [Blue]As[/Blue] [Blue]String[/Blue] = [Red]""[/Red]
        [Blue]Dim[/Blue] _Seperator [Blue]As[/Blue] [Blue]String[/Blue] = [Red]""[/Red]
        [Blue]Dim[/Blue] _Seperator2 [Blue]As[/Blue] [Blue]String[/Blue] = [Red]""[/Red]
        [Blue]Dim[/Blue] _Seperator3 [Blue]As[/Blue] [Blue]String[/Blue] = [Red]""[/Red]
        [Blue]Dim[/Blue] _Regex [Blue]As[/Blue] System.Text.RegularExpressions.Regex
        [Blue]Dim[/Blue] _Match [Blue]As[/Blue] System.Text.RegularExpressions.Match
        [Blue]Try[/Blue]
            _TextSelection = DTE.ActiveDocument.Selection
            _OriginalCode = _TextSelection.Text
            _Lines = Split(_OriginalCode, vbLf)
            _Regex = [Blue]New[/Blue] System.Text.RegularExpressions.Regex([Red]"(Dim|Private)\s*(?<varname>\S*)\s*As\s*(?<typename>\S*)"[/Red], System.Text.RegularExpressions.RegexOptions.IgnoreCase Or System.Text.RegularExpressions.RegexOptions.IgnoreCase.ExplicitCapture)
            [Green]'Add regions to private members[/Green]
            _TextSelection.Delete()
            _TextSelection.Insert(vbCrLf & [Red]"#Region "[/Red][Red]" Private members "[/Red][Red]""[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            [Blue]For[/Blue] Each _Line In _Lines
                _Line = _Line.Trim
                [Blue]If[/Blue] Not _Line = [Red]""[/Red] [Blue]Then[/Blue]
                    _Match = _Regex.Match(_Line)
                    [Blue]If[/Blue] _Match.Success [Blue]Then[/Blue]
                        _DataType = _Match.Groups([Red]"typename"[/Red]).Value.Trim
                        _VariableName = _Match.Groups([Red]"varname"[/Red]).Value.Trim
                        [Blue]If[/Blue] _VariableName.StartsWith([Red]"_"[/Red]) [Blue]Then[/Blue]
                            _PublicName = _VariableName.Substring(1, 1).ToUpper & _VariableName.Substring(2)
                            _Procedure = [Blue]String[/Blue].Format([Red]"Private {0} As {1}"[/Red], _VariableName, _DataType)
                            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"''' <summary>"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
                            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"''' A local variable called "[/Red] & _VariableName & [Red]" of type "[/Red] & _DataType, vsInsertFlags.vsInsertFlagsInsertAtEnd)
                            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"''' </summary>"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
                            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"''' <remarks>Has Property "[/Red] & _PublicName & [Red]"</remarks>"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
                            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & _Procedure, vsInsertFlags.vsInsertFlagsInsertAtEnd)
                            _Seperator = [Red]" - "[/Red]
                        [Blue]Else[/Blue]
                            MsgBox([Red]"The property "[/Red] & _VariableName & [Red]" should begin with an underscore."[/Red], MsgBoxStyle.Critical, [Red]"ConvertProperties"[/Red])
                        [Blue]End[/Blue] [Blue]If[/Blue]
                    [Blue]End[/Blue] [Blue]If[/Blue]
                [Blue]End[/Blue] [Blue]If[/Blue]
            [Blue]Next[/Blue]
            _TextSelection.Insert(vbCrLf & [Red]"#End Region"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            [Green]' Add construcotrs[/Green]
            _Seperator = [Red]""[/Red]
            _Seperator2 = [Red]""[/Red]
            _TextSelection.Insert(vbCrLf & vbCrLf & [Red]"#Region "[/Red][Red]" Constructors "[/Red][Red]""[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"''' <summary>"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"''' Default empty constructor"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"''' </summary>"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"''' <remarks></remarks>"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"Public Sub New()"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & [Red]"'Implement default constructor"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"End Sub"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf, vsInsertFlags.vsInsertFlagsInsertAtEnd)
            [Blue]For[/Blue] Each _Line In _Lines
                _Line = _Line.Trim
                [Blue]If[/Blue] Not _Line = [Red]""[/Red] [Blue]Then[/Blue]
                    _Match = _Regex.Match(_Line)
                    [Blue]If[/Blue] _Match.Success [Blue]Then[/Blue]
                        _DataType = _Match.Groups([Red]"typename"[/Red]).Value.Trim
                        _VariableName = _Match.Groups([Red]"varname"[/Red]).Value.Trim
                        [Blue]If[/Blue] _VariableName.StartsWith([Red]"_"[/Red]) [Blue]Then[/Blue]
                            _PublicName = _VariableName.Substring(1, 1).ToUpper & _VariableName.Substring(2)
                            _Declarations &= _Seperator & [Red]"ByVal "[/Red] & _PublicName & [Red]" As "[/Red] & _DataType
                            _DocTags &= _Seperator2 & [Red]"''' <param name="[/Red][Red]""[/Red] & _PublicName & [Red]""[/Red][Red]">DataType = "[/Red] & _DataType & [Red]"</param>"[/Red]
                            _Fills &= [Blue]String[/Blue].Format(_Seperator3 & [Red]"me.{0} = {1}"[/Red], _PublicName, _VariableName)
                            _Seperator = [Red]", "[/Red]
                            _Seperator2 = vbCrLf & ControlChars.Tab & ControlChars.Tab
                            _Seperator3 = vbCrLf & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab
                        [Blue]Else[/Blue]
                            MsgBox([Red]"The property "[/Red] & _VariableName & [Red]" should begin with an underscore."[/Red], MsgBoxStyle.Critical, [Red]"ConvertProperties"[/Red])
                        [Blue]End[/Blue] [Blue]If[/Blue]
                    [Blue]End[/Blue] [Blue]If[/Blue]
                [Blue]End[/Blue] [Blue]If[/Blue]
            [Blue]Next[/Blue]
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"''' <summary>"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"''' Constructor with all the fields"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"''' </summary>"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & _DocTags, vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"''' <remarks></remarks>"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"Public Sub New("[/Red] & _Declarations & [Red]")"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & _Fills, vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"End Sub"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & [Red]"#End Region"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf, vsInsertFlags.vsInsertFlagsInsertAtEnd)
            [Green]' Add Properties[/Green]
            _Seperator = [Red]""[/Red]
            _Seperator2 = [Red]""[/Red]
            _TextSelection.Insert(vbCrLf & [Red]"#Region "[/Red][Red]" Public properties "[/Red][Red]""[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            [Blue]For[/Blue] Each _Line In _Lines
                _Line = _Line.Trim
                [Blue]If[/Blue] Not _Line = [Red]""[/Red] [Blue]Then[/Blue]
                    _Match = _Regex.Match(_Line)
                    [Blue]If[/Blue] _Match.Success [Blue]Then[/Blue]
                        _VariableName = _Match.Groups([Red]"varname"[/Red]).Value.Trim
                        [Blue]If[/Blue] _VariableName.StartsWith([Red]"_"[/Red]) [Blue]Then[/Blue]
                            _DataType = _Match.Groups([Red]"typename"[/Red]).Value.Trim
                            _PublicName = _VariableName.Substring(1, 1).ToUpper & _VariableName.Substring(2)
                            _Procedure = [Blue]String[/Blue].Format( _
                            _Seperator & _
                            ControlChars.Tab & ControlChars.Tab & [Red]"''' <summary>{0}"[/Red] _
                            & ControlChars.Tab & ControlChars.Tab & [Red]"''' This is the {1} property.{0}"[/Red] _
                            & ControlChars.Tab & ControlChars.Tab & [Red]"''' </summary>{0}"[/Red] _
                            & ControlChars.Tab & ControlChars.Tab & [Red]"''' <value>"[/Red] & _DataType & [Red]"</value>{0}"[/Red] _
                            & ControlChars.Tab & ControlChars.Tab & [Red]"''' <returns>"[/Red] & _DataType & [Red]"</returns>{0}"[/Red] _
                            & ControlChars.Tab & ControlChars.Tab & [Red]"''' <remarks></remarks>{0}"[/Red] _
                            & ControlChars.Tab & ControlChars.Tab & [Red]"Public Property {1} As {2}{0}"[/Red] _
                            & ControlChars.Tab & ControlChars.Tab & [Red]"    Get{0}"[/Red] _
                            & ControlChars.Tab & ControlChars.Tab & [Red]"        Return {3}{0}"[/Red] _
                            & ControlChars.Tab & ControlChars.Tab & [Red]"    End Get{0}"[/Red] _
                            & ControlChars.Tab & ControlChars.Tab & [Red]"    Set(ByVal Value As {2}){0}"[/Red] _
                            & ControlChars.Tab & ControlChars.Tab & [Red]"        {3} = Value{0}"[/Red] _
                            & ControlChars.Tab & ControlChars.Tab & [Red]"    End Set{0}"[/Red] _
                            & ControlChars.Tab & ControlChars.Tab & [Red]"End Property"[/Red], vbCrLf, _PublicName, _DataType, _VariableName)
                            _TextSelection.Insert(vbCrLf & _Procedure, vsInsertFlags.vsInsertFlagsInsertAtEnd)
                            _Seperator = [Red]"{0}"[/Red]
                        [Blue]Else[/Blue]
                            MsgBox([Red]"The property "[/Red] & _VariableName & [Red]" should begin with an underscore."[/Red], MsgBoxStyle.Critical, [Red]"ConvertProperties"[/Red])
                        [Blue]End[/Blue] [Blue]If[/Blue]
                    [Blue]End[/Blue] [Blue]If[/Blue]
                [Blue]End[/Blue] [Blue]If[/Blue]
            [Blue]Next[/Blue]
            _TextSelection.Insert(vbCrLf & [Red]"#End Region"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            [Green]' Add ToString[/Green]
            _Seperator = [Red]""[/Red]
            _Seperator2 = [Red]""[/Red]
            _TextSelection.Insert(vbCrLf & vbCrLf & [Red]"#Region "[/Red][Red]" Overrides ToString "[/Red][Red]""[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"''' <summary>"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"''' Overridden ToString method for this class"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"''' </summary>"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"''' <returns>String</returns>"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"''' <remarks>The String value of this class represented by the ToStrings of all it's private members</remarks>"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"Public Overrides Function ToString() As String"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & [Red]"Dim ReturnString As New System.Text.StringBuilder()"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            [Blue]For[/Blue] Each _Line In _Lines
                _Line = _Line.Trim
                [Blue]If[/Blue] Not _Line = [Red]""[/Red] [Blue]Then[/Blue]
                    _Match = _Regex.Match(_Line)
                    [Blue]If[/Blue] _Match.Success [Blue]Then[/Blue]
                        _VariableName = _Match.Groups([Red]"varname"[/Red]).Value.Trim
                        [Blue]If[/Blue] _VariableName.StartsWith([Red]"_"[/Red]) [Blue]Then[/Blue]
                            _PublicName = _VariableName.Substring(1, 1).ToUpper & _VariableName.Substring(2)
                            _Procedure = [Blue]String[/Blue].Format([Red]"ReturnString.Append("[/Red][Red]""[/Red] & _Seperator & [Red]"[{0}: "[/Red][Red]" & {1}.ToString() & "[/Red][Red]"]"[/Red][Red]")"[/Red], _PublicName, _VariableName)
                            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & _Procedure, vsInsertFlags.vsInsertFlagsInsertAtEnd)
                            _Seperator = [Red]" - "[/Red]
                        [Blue]Else[/Blue]
                            MsgBox([Red]"The property "[/Red] & _VariableName & [Red]" should begin with an underscore."[/Red], MsgBoxStyle.Critical, [Red]"ConvertProperties"[/Red])
                        [Blue]End[/Blue] [Blue]If[/Blue]
                    [Blue]End[/Blue] [Blue]If[/Blue]
                [Blue]End[/Blue] [Blue]If[/Blue]
            [Blue]Next[/Blue]
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & [Red]"Return ReturnString.ToString()"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & ControlChars.Tab & ControlChars.Tab & [Red]"End Function"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & [Red]"#End Region"[/Red], vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.Insert(vbCrLf & vbCrLf, vsInsertFlags.vsInsertFlagsInsertAtEnd)
            _TextSelection.SmartFormat()
        [Blue]Catch[/Blue] ex [Blue]As[/Blue] System.Exception
            MsgBox([Red]"There was an error while constructing code: "[/Red] & _
            ex.ToString & [Red]"."[/Red], MsgBoxStyle.Critical, [Red]"Construct Class"[/Red])
        [Blue]End[/Blue] [Blue]Try[/Blue]
        DTE.UndoContext.Close()
    [Blue]End[/Blue] [Blue]Sub[/Blue]

Christiaan Baes
Belgium

"My new site" - Me
 
Is there a way in VS2k5 to use your macro script in the IDE?

What do you mean?

In VS2005 I just select the private members and doubleclick on the macroname and it starts running.

BTW ndoc doesn't support VS2005 but you can use SandCastle instead which has all the same features.

Christiaan Baes
Belgium

"My new site" - Me
 
That's what I've been hearing about nDoc/SandCastle. Although my management see's "no advantage" to upgrading from VS2k2. When is MS scheduling an end of support for 2k2 anyway?

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Close! I just looked it up:

Code:
Products Released       |  Availability Date  |  Mainstream Retired  |  Extended Retired
------------------------+---------------------+----------------------+------------------
VS.NET 2k2 Academic     |  4/15/2002          |  7/10/2007           |  7/14/2009
VS.NET 2k2 Architect    |  4/15/2002          |  7/10/2007           |  7/14/2009
VS.NET 2k2 Developer    |  4/15/2002          |  7/10/2007           |  7/14/2009
VS.NET 2k2 Professional |  4/15/2002          |  7/10/2007           |  7/14/2009

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top