This is a well known log analyzer application that can provide a nice web interface for viewing we stats.
Category Archives: Programming Tools
VS2005 VB.Net Create Properties From Private Fields
“Refactor!” has the ability to turn your fields into public accessible properties, but it kinda sucks because 1) you have to do it 1 at a time, and 2) the naming convetion is all wrong.
For example if you have a private integer called myInt then your property will be MyInt1. Not exaclty what I am looking for.
So I updated my 2002 macro for creating these properties. It should allow you to follow a variety of naming conventions “m_XXX”, “ciXXX”, “strXXX” etc.
Just include the macro below, then just highlight your private fields, and run the macro.
' highlight the private properties
Public Sub AddClassProperties()
Dim oTextSelection As TextSelection = DTE.ActiveWindow.Selection
Dim iLinesSelected = oTextSelection.TextRanges.Count
Dim colPropertyList As New Collection()
Dim iIndex As Integer
Dim oStart As EditPoint = oTextSelection.TopPoint.CreateEditPoint()
Dim oEnd As TextPoint = oTextSelection.BottomPoint
'Create an Undo context object so all the changes can be
'undone by CTRL+Z
Dim oUnDo As UndoContext = DTE.UndoContext
'Supress the User Interface. This will make it run faster
'and make all the changes appear once
DTE.SuppressUI = True
Try
oUnDo.Open("Comment Line")
Dim sProperty As String
Dim sLineOfText As String
Do While (oStart.LessThan(oEnd))
sLineOfText = oStart.GetText(oStart.LineLength).Trim
'*** do some kind of simple check to make sure that this line
'*** isn't blank and isn't some other kind of code or comment
If (sLineOfText.IndexOf(" As ") >= 0 And ( _
(sLineOfText.IndexOf("Public ") >= 0) Or _
(sLineOfText.IndexOf("Private ") >= 0) Or _
(sLineOfText.IndexOf("Dim ") >= 0) Or _
(sLineOfText.IndexOf("Protected ") >= 0) Or _
(sLineOfText.IndexOf("Friend ") >= 0) Or _
(sLineOfText.IndexOf("ReDim ") >= 0) Or _
(sLineOfText.IndexOf("Shared ") >= 0) Or _
(sLineOfText.IndexOf("Static ") >= 0) _
)) Then
sProperty = oStart.GetText(oStart.LineLength).Trim.Replace(" New ", " ").Replace("()", "")
colPropertyList.Add(sProperty)
End If
oStart.LineDown()
oStart.StartOfLine()
Loop
If colPropertyList.Count > 0 Then
For Each sProperty In colPropertyList
Call InsertProperty(sProperty)
Next
Else
MsgBox("You must select the class properties")
End If
Catch ex As System.Exception
Debug.WriteLine(ex)
If MsgBoxResult.Yes = MsgBox("Error: " & ex.ToString & vbCrLf & "Undo Changes?", MsgBoxStyle.YesNo) Then
oUnDo.SetAborted()
End If
Return
Finally
'If an error occured, then need to make sure that the undo context is cleaned up.
'Otherwise, the editor can be left in a perpetual undo context
If oUnDo.IsOpen Then
oUnDo.Close()
End If
DTE.SuppressUI = False
End Try
End Sub
Private Sub InsertProperty(ByVal sProp As String)
Dim oTextSelection As TextSelection = DTE.ActiveWindow.Selection
Dim sMember As String = sProp.Substring(sProp.IndexOf(" ")).Trim
Dim sDataType As String
Dim sName As String
Dim i As Integer
Dim iAscVal As Integer
i = sMember.IndexOf("(")
If Not i = -1 Then
sMember = sMember.Substring(0, i)
End If
i = sMember.IndexOf("=")
If Not i = -1 Then
sMember = sMember.Substring(0, i)
End If
sDataType = sMember.Substring(sMember.IndexOf(" As ") + 1)
For i = 0 To sMember.Length - 1
'iAscVal = Asc(Mid(sName, i, 1))
iAscVal = Asc(sMember.Chars(i))
If iAscVal > 64 And iAscVal < 91 Then
sName = sMember.Substring(i)
Exit For
End If
Next i
sName = sName.Substring(0, sName.IndexOf(" As ") + 1).Trim
If sName.Length = 0 Then
MsgBox("Unable to process the class property: " & sMember & ". This is usually caused by an incorrect naming convention (e.g. not cxName)")
Return
End If
sMember = sMember.Substring(0, sMember.Length - sDataType.Length).Trim
With oTextSelection
.MoveToPoint(.ActivePoint.CodeElement(vsCMElement.vsCMElementClass).GetEndPoint(vsCMPart.vsCMPartWhole))
.LineUp()
.EndOfLine()
.Text = "Public Property " & sName & "() " & sDataType
.NewLine()
.Text = "Return " & sMember
.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn, True)
.Copy()
.LineDown(False, 3)
DTE.ExecuteCommand("Edit.Paste")
.Text = "Me." & sMember & " = Value"
.LineDown(False, 2)
.NewLine(2)
End With
End Sub
Update1: When using code that you cut and paste from here, you might need to first paste it into Word or Wordpad.
Update2: When using this macro, you need a space (new line) between the last private field variable and your end of class line.
App.Config functionality for Class Library Assembiles
I was just reading this site:
http://www.bearcanyon.com/dotnet/#AssemblySettings
I downloaded the sample code (link below). It is supposed to allow you to have a config file per assembley e.g. MyAssembly.dll.config.
I haven’t looked at the code, but I guess you would just write something that uses reflection to find the assembly name, and then look for an xml file to read.
AssemblySettings.zip (10.5 KB)
Implementing System.ICloneable and a Snippet
This will provide the necessary functions to implement ICloneable as well as a type specific Clone method.
Public Function Clone() As ClassName
Dim bFormatter As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim stream As New System.IO.MemoryStream()
bFormatter.Serialize(stream, Me)
stream.Seek(0, System.IO.SeekOrigin.Begin)
Dim newClone As ClassName
newClone = CType(bFormatter.Deserialize(stream), ClassName)
Return newClone
End Function
Private Function ICloneableImplementation() As Object Implements System.ICloneable.Clone
Return Me.Clone
End Function
I wrapped this into a snippet that you can import into Visual Studio 2005.
Quickbooks Integration
AcctSync is a .NET SDK for integrating stuff into quickbooks.
Update: I first made this post in 2003, but I have another client that is going to be looking to do something with Quickbooks. Might want to revisit this component in the near future.
Troubleshooting .NET Applications – Knowing Which Tools to Use and When
This whitepaper: Troubleshooting .NET Applications – Knowing Which Tools to Use and When talks about different methods for debugging .net applications, and talks about the various tools available to aid in the debugging efforst.