Use the Vs. Net macro to generate property definitions based on private variables to accelerate development

Source: Internet
Author: User
Compile Code The property definition is often generated based on the defined private variables. This operation can be implemented using the Vs. Net macro, the Code is as follows: Sub temporarymacro () Sub Temporarymacro ()
Dim TS As Textselection = DTE. activedocument. Selection
Dim Insertion As   String , Line As   String
Dim Lines () As   String   = TS. Text. Split (vbnewline) ' Returns the attribute process for each row of the selected part.
Insertion = Vbnewline
For   Each Line In Lines
Insertion & = Getinsertion (line)
Next
If (Insertion. Length >   1 ) Then
TS. endofline ()
TS. newline ()
TS. insert (insertion)
End   If
End sub
Private   Function Getinsertion ( Byval Text As   String ) As   String
Dim Words () As   String   = Text. Trim. Split ()
If Words. Length <   3   Then ' This row content is not a valid variable Declaration
Return   ""
Else
Dim Insertion As   String
Insertion & = Vbtab & Vbtab &   " /// <Summary> "
Insertion & = Vbnewline
Insertion & = Vbtab & Vbtab &   " /// "
Insertion & = Vbnewline
Insertion & = Vbtab & Vbtab &   " /// </Summary> " ' If you do not want XML comments, you can skip these lines.
Insertion & = Vbnewline
Insertion & = Vbtab & Vbtab &   " Public "   & Words ( 1 ) &   "   "   & Words ( 2 ). Trimstart ( " M " ). Trimstart ( " _ " ) .. Trimend ( " ; " ) ' My private variables start with "M _".
Insertion & = Vbnewline
Insertion & = Vbtab & Vbtab &   " { "
Insertion & = Vbnewline
Insertion & = Vbtab & Vbtab & Vbtab &   " Get {return "   & Words ( 2 ) &   " } "
Insertion & = Vbnewline
Insertion & = Vbtab & Vbtab & Vbtab &   " Set { "   & Words ( 2 ). Trimend ( " ; " ) &   " = Value ;} "
Insertion & = Vbnewline
Insertion & = Vbtab & Vbtab &   " } "
Insertion & = Vbnewline
Return Insertion
End   If
End Function

Put the above Code in the Vs. Net macro, select the defined private variable, and then Ctrl + Shift + P to generate the property definition based on the custom private variable.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.