开发者

Using reflection to determine if a control supports an event

开发者 https://www.devze.com 2023-02-15 20:59 出处:网络
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?

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
0

精彩评论

暂无评论...
验证码 换一张
取 消