Tuesday, November 25, 2008

fedora 10 released

Yesterday the fedora 10 released. click Here to download it.

Generate properties from class variables

One of the nice thing about Visual studio is its macro support. You can create and use macros in visaul studio .net to increase the productivity. One feature which most developers wants a quick property generation from list of class variables but Visual Studio .NET has no shortcut for it. To achieve this, you have record or create a macro.

So below is the Macro that generate the automatic properties from the member variables.

Just copy the text below and then open VS.NET.Go to Tools-> Macro->Macros IDE menu item.
A new window will be open. click on mymacros and paste the below text and build it.

After building, open your VS project. Go to Tools->Options. A dialog will be appeard. click on keyboard in Environment. Select your macro and assign a shortcut. For example Shift + F2.

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Imports System.Text

Public Module Expand
Public Sub ExpandPrivateMembersFronSelection()
Dim TS As TextSelection =

Dim strResult As String, Line As String
Dim Lines() As String =

For Each Line In Lines
strResult &= GetstrResult(Line)
TS.Insert(vbCrLf & "#region ""Public

Properties""" & vbCrLf & strResult &

"#endregion" & vbCrLf)

End Sub

Private Function GetstrResult(ByVal text As

String) As String
If (text.Contains("private")) Then
text = text.Replace("private",

End If
If (text.Contains(";")) Then
text = text.Replace(";", "")
End If
Dim words() As String =


If words.Length < 2 Then
Return ""
Dim strResult As New


strResult.AppendLine(String.Format("public {0}

{1}", words(0), StrConv(words(1)(0),

VbStrConv.ProperCase)) & words(1).Substring(1))
strResult.AppendLine(vbTab & "{

get { ")
strResult.AppendLine(vbTab &

vbTab & "return " & words(1) & ";")
strResult.AppendLine(vbTab &


strResult.AppendLine(String.Format(vbTab &

strResult.AppendLine(vbTab &

vbTab & " { " & words(1) & " = value;")
strResult.AppendLine(vbTab &

Return strResult.ToString
End If
Catch ex As Exception


End Try

End Function

End Module

Currently it will gives you incorrect result if the input is

string p = string.Empty;

You can customize macro according to your needs. The valid inputs are

string p;

private string q;

Just select and press your assigned shortcut.