Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Parameters to Properties Gift
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Parameters to Properties Gift
Divers
Thread ID:
01099655
Message ID:
01099655
Vues:
41
Hello UT,
Here is a gift from me to the UT. I have been converting logical function groups that accept large numbers of parameters into classes with methods. Below is a regex that works in the VS find and replace window to convert the params into properties. I didn't overburden the thing with the optional keyword but you could easily add that if you cared. Notice the spaces in the output are not escaped, yet the input was.

This is how I made it work in the find and replace for both VS 2005 and VS 2003.

This is not laziness... Its efficiency of thought and motion. :p

RegIn:
(ByRef|ByVal)\ {.*}\ As\ {.*}(\,\ \_|\,\ |\,)<\pre>
RegOut: 
<pre>Private \_\1 as \2 \nPublic Property \1 As \2 \n Get \n Return \_\1 \n End Get \n Set(ByVal value as \2) \n _\1 = value \n End Set \n End Property \n\n
Unfortunately they all have to be on their own line. Running against the following:
ByRef strMask As String , _
ByVal MatchCase As RegexOptions, _
ByRef strPrefix As String, 
ByVal bolSubDirs As System.IO.SearchOption ,
Yields:
    Private _strMask As String
    Public Property strMask() As String
        Get
            Return _strMask
        End Get
        Set(ByVal value As String)
            _strMask = value
        End Set
    End Property


    Private _MatchCase As RegexOptions
    Public Property MatchCase() As RegexOptions
        Get
            Return _MatchCase
        End Get
        Set(ByVal value As RegexOptions)
            _MatchCase = value
        End Set
    End Property


    Private _strPrefix As String
    Public Property strPrefix() As String
        Get
            Return _strPrefix
        End Get
        Set(ByVal value As String)
            _strPrefix = value
        End Set
    End Property


    Private _bolSubDirs As System.IO.SearchOption
    Public Property bolSubDirs() As System.IO.SearchOption
        Get
            Return _bolSubDirs
        End Get
        Set(ByVal value As System.IO.SearchOption)
            _bolSubDirs = value
        End Set
    End Property
Enjoy,
~Joe Johnston USA

"If ye love wealth better than liberty, the tranquility of servitude better than the animated contest of freedom, go home from us in peace. We ask not your counsel or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
~Samuel Adams

Répondre
Fil
Voir

Click here to load this message in the networking platform