Overkill or Useless: You Decide!

Back to Listing

Overkill or Useless: You Decide!

30 Jan, 2009

Here is the gist of what I was trying to accomplish. Please excuse the VB.. it's not by choice. 8)

Basically the page I was working on has a set of switch statements based on string literals which annoys me.. So I was messing around with a way to use Enumerations to represent my commands. But the commands come back as strings from the various page controls.. So I was looking at a way to generically re-map back to the command Enumeration.

Private Function GetCommand(Of T)(ByVal commandName As String) As T  
  Return CType([Enum].Parse(GetType(T), commandName), T)
End Function

Protected Enum GridCommand  
End Enum

Public Overrides Sub Grid_Commands(ByVal source As Object, _  
                                     ByVal e As DataGridCommandEventArgs) _
                                     Handles CompetencyData.ItemCommand, FormData.ItemCommand
  If Page_Save() Then

    Select Case GetCommand(Of GridCommand)(e.CommandName)

      Case GridCommand.CompetencySelect
        NavigateToCompetencySelection( _
         CInt(CompetencyData.DataKeys(e.Item.ItemIndex)), _

      Case GridCommand.FormSelect
        NavigateToFormSelection( _
         CInt(FormData.DataKeys(e.Item.ItemIndex)), _

    End Select
  End If

End Sub  
Share this story

Bobby Johnson

About Author

I am a passionate engineer with an interest in shipping quality software, building strong collaborative teams and continuous improvement of my skills, team and the product.

comments powered by Disqus
Back to top