Wrox Programmer Forums
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 16th, 2008, 08:20 AM
Authorized User
Join Date: Feb 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts

Here is macro to generate the property code for VB.Net:

Sub GeneratePropertyCode()
        Dim FieldDetailList As New System.Collections.ArrayList
        Dim FieldName, FieldDataType As String

        While True
            DTE.ActiveDocument.Selection.StartOfLine(vsStartOf LineOptions.vsStartOfLineOptionsFirstText)
            If Left(DTE.ActiveDocument.Selection.Text, 9) = "Private _" Then
                FieldDetailList.Add(DTE.ActiveDocument.Selection.T ext)
                DTE.ActiveDocument.Selection.LineDown(False, 1)
                Exit While
            End If
        End While

        For i As Integer = 0 To FieldDetailList.Count - 1
            FieldName = Mid(FieldDetailList(i).ToString(), 10, InStr(FieldDetailList(i).ToString(), " As") - 10)
            FieldDataType = Mid(FieldDetailList(i).ToString(), InStr(FieldDetailList(i).ToString(), "As ") + 3, 50)
            DTE.ActiveDocument.Selection.Text = "Public Property " & FieldName & " as " & FieldDataType
            DTE.ActiveDocument.Selection.Text = "Return _" & FieldName
            DTE.ActiveDocument.Selection.LineDown(False, 3)
            DTE.ActiveDocument.Selection.Text = "Value = _" & FieldName
            DTE.ActiveDocument.Selection.LineDown(False, 2)
    End Sub

Try out on this class:
Public Class Student

    Private _Id As Integer
    Private _Name As String
    Private _BirthDate As Date

End Class

You need to place the cursor on the line where first private variable declared and then run the macro GeneratePropertyCode. Please note some code is hardcoded in macro, you can modify according to your need.

Pooja Falor

Similar Threads
Thread Thread Starter Forum Replies Last Post
C# Auto Generate Codes lasith C# 0 February 23rd, 2007 02:25 AM
how to auto generate date? okboy SQL Server 2000 3 December 12th, 2006 08:17 PM
Auto generate no mateenmohd Classic ASP Basics 3 June 11th, 2006 07:06 AM
Auto generate? nikryden BOOK: Beginning VB.NET Databases 2 December 19th, 2005 12:43 PM
auto generate an number utarian Access 2 March 28th, 2005 02:24 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.