I've written a small utility function for our base page, it works fine in most cases, but if it's called in the form SetDropDownValue(dropdown, Nothing, True)
I have to specify the type T.
Since the compiler only requires a type specified when the type is not used, I'm wondering if there is a better way to write the code.
The method is as follows:
Protected Sub SetDropDownValue(Of T As Structure)(ByVal target As DropDownList, ByVal value As Nullable(Of T), ByVal bindFirst As Boolean)
If target Is Nothing Then
Throw New ArgumentNullException("target")
End If
If bindFirst Then
target.DataBind()
End If
If value.HasValue Then
target.SelectedValue = value.Value.ToString()
Else
target.SelectedIndex = 0
End If
End Sub
What is a better way to code this method?