Tuesday, September 27, 2005

WinFX Developer Center: InfoCard: The Laws of Identity

WinFX Developer Center: InfoCard: The Laws of Identity: "The Laws of Identity"

Wednesday, September 21, 2005

Fields to Properties (Visual Studio.Net)

Yes, we miss Automatic property generation from the Fields of the classes in the Visual Studio.net IDE.
Following is the sample code of the Macro, I am telling here which I used for myself.
This member variable to Property generation is not generic and is very difficult to be. The idea is that I demonstrate to do it my way and you can customize it for your needs.

Code is in the Visual Basic.Net
--------------------------------------------------
NEED:

Public Class AClass

#Region "Members"
Private strStaffId As String
Private strStaffName As String
#End Region

End Class

-->
Public Class AClass

#Region "Members"
Private strStaffId As String
Public Property StaffId() As String
Get
Return strStaffId
End Get
Set(ByVal Value As String)
strStaffId = Value
End Set
End Property

Private strStaffName As String
Public Property StaffId() As String
Get
Return strStaffId
End Get
Set(ByVal Value As String)
strStaffId = Value
End Set
End Property

#End Region

End Class

--------------------------------------------------

The first step in using a macro to generate code is to open the Macros IDE, add a new module, a macro, and stub out the code template.

1. To create a new macro, open Visual Studio .NET—I am using VS.NET 2003, but the example works in version 1—and select Tools|Macros|Macros IDE
2. In the Macros Project Explorer click on the MyMacros project, right-clicking Add|Add Module from the Project Explorer context menu
3. Add a public subroutine named WriteProperty to the module

So, In my case it is like:
File:- MyModule
Imports EnvDTE
Imports System
Imports System.Diagnostics

Public Module MyModule

Private Cr As String = Environment.NewLine

Private mask As String = _
"Public Property {0}() As {1}" + Cr + _
" Get" + Cr + _
" Return {2}" + Cr + _
" End Get" + Cr + _
" Set(ByVal Value As {1})" + Cr + _
" {2} = Value" + Cr + _
" End Set" + Cr + _
" End Property" + Cr

Public Sub WriteProperty()
Dim Selection As TextSelection = DTE.ActiveDocument.Selection

Dim FieldName As String
Dim PropertyName As String
Dim PropertyType As String

FieldName = Selection.Text
PropertyName = FieldName.Substring(3) 'skip strUserName -> UserName

Selection.EndOfLine()
Selection.WordLeft(True)
PropertyType = Selection.Text
Selection.EndOfLine()
Selection.NewLine(2)

Dim vp As VirtualPoint = Selection.ActivePoint
Selection.Insert(String.Format(mask, PropertyName, PropertyType, FieldName))
End Sub
End Module
-----------------------------------------------------------------------

Now, You can customize the VisualStudio environment and put a button on a toolbar and that button can call our macro. You can also assign a hot key to call this code.
To generate the property for the field, You only have to select the field and it will generate its code for the corresponding property.

When done, you only need to edit this code according to your needs.

bye
:)

Saturday, September 03, 2005

XML documentation in Visual Basic.NET applications

By default VB.Net in VS.net is missing support for automated generation of the documentation from with in the source, Like Recommended Tags for Documentation Comments.
Here 'VBCommenter' PowerToy from the Got Dot Net Web site can help us. With VBCommenter plug-in, they can create XML documentation as they are writing code.
To use this facility, it's first necessary to install VBCommenter. The download is a ZIP file that includes a standard Setup.exe file with an accompanying .msi file; it's trivial to unpack and install and should take no more than two minutes. Configure VBCommenter settings from the Tools VBCommenter Options menu. Here, make sure the checkboxes for both "Create .xml files when projects are built" and "Insert XML comments in source" are checked.
Once the plug-in is running and configured, simply key three apostrophes into the Start Page for any class definition, property, member variable, or method.

Because documenting as you go is the best way to make sure all the nuances of the code are captured, this technique (and the VBCommenter tool) are highly recommended for those seeking an easy way to add structured documentation to their work.

For a bit advance work, VBCommenter can be customized as described here : Customizing The VBCommenter Power Toy

MSDN TV Episode talks about "Data Access in ASP.NET 2.0"






MSDN TV: Data Access in ASP.NET 2.0
:

Data Access in ASP.NET 2.0


Bradley Millington shows how to build a data-driven Web site in ASP.NET 2.0 and Visual Studio 2005.
Learn how to build a database from scratch using Visual Studio built-in support for SQL Server 2005 Express,
then retrieve and render the database contents using the new data controls in ASP.NET.


--------------------------------------------------------------------------------
Hammad Rajjoub,
MVP (Windows Server System - XML Web Services),
User Group Leader - Dot Net Wizards (http://dotnetwizards.blogspot.com),
Chariman UG Relations Committee (http://www.inetapakistan.org),
Member Speakers Bureau (http://mea.ineta.org)