Using reflection to determine if a control supports an event
To avoid the try-catch block, is there a way to determine if a control supports the specified event without having a try-catch block?
Dim d As [Delegate] = [Delegate].CreateDelegate(eventHandler.EventHandlerType, _
Me, _
开发者_运维知识库 "OnControlValueChanged") '<<
Use reflection:
Dim events As System.Reflection.EventInfo() = GetType(Control).GetEvents()
For Each someEvent As System.Reflection.EventInfo In events
If someEvent.Name = "OnControlValueChanged" Then
'Do what you need to do
End If
Next
精彩评论