为什么要这么长?
你可以用更简单的方法完成同样的事情:
Private _ToolTipList As New List(Of ToolTip)
<Extension()> _
Public Function CreateForm(ByVal formType As Type) As Form
If (formType Is Nothing) Then
Throw New ArgumentNullException("formType")
End If
If (Not GetType(Form).IsAssignableFrom(formType)) Then
Throw New InvalidOperationException _
(String.Format("The type '{0}' is not a form.", formType.FullName))
End If
Dim ctor = formType.GetConstructor(New Type() {})
If (ctor Is Nothing) Then
Throw New InvalidOperationException _
(String.Format _
("The type '{0}' does not have a public default constructor.", _
formType.FullName))
End If
Dim frm As Form = ctor.Invoke(New Object() {})
Dim toolTip As New ToolTip(New Container())
LoadToolTipData(toolTip, frm)
_ToolTipList.Add(toolTip)
Return frm
End Function
Private Sub LoadToolTipData(ByVal toolTip As ToolTip, _
ByVal ctrl As Control, _
Optional ByVal parentHierarchy As String = "")
Dim currentHierarchy = parentHierarchy & "." & ctrl.Name
Dim toolTipText = LoadDataFromDb(currentHierarchy)
If Not String.IsNullOrEmpty(toolTipText) Then
toolTip.SetToolTip(ctrl, toolTipText)
End If
For Each c As Control In ctrl.Controls
LoadToolTipData(toolTip, c, currentHierarchy)
Next
End Sub
Private Function LoadDataFromDb(ByVal key As String) As String
Return String.Empty
End Function