Existence of Method

  • Thread starter Thread starter Ken Kast
  • Start date Start date
K

Ken Kast

I have a class in which a specific event handler is passed in as a callback.
I want to be able to determine at run time for a specific instance of the
class whether or not the event handler has been defined. I can use a
private attribute as a flag, but is there any way in general to determine
the existence of a method, or at least an event handler?

Ken
 
Ken Kast said:
I have a class in which a specific event handler is passed in as a
callback. I want to be able to determine at run time for a specific
instance of the class whether or not the event handler has been
defined. I can use a private attribute as a flag, but is there any
way in general to determine the existence of a method, or at least an
event handler?

Could you please give us a short example to see your intention?
 
* "Ken Kast said:
I have a class in which a specific event handler is passed in as a callback.
I want to be able to determine at run time for a specific instance of the
class whether or not the event handler has been defined. I can use a
private attribute as a flag, but is there any way in general to determine
the existence of a method, or at least an event handler?

You can determine the number of registered event handlers:

\\\
Public Class Main
Public Shared Sub Main()
Dim c As New FooBar()
AddHandler c.Foo, AddressOf Goo
c.AddSampleHandler()
c.AddSampleHandler()
Console.WriteLine( _
"Anzahl der Handler für Foo: {0}", _
c.NumberOfFooHandlers _
)
RemoveHandler c.Foo, AddressOf Goo
Console.Read()
End Sub

Private Shared Sub Goo()
End Sub
End Class

Public Class FooBar
Public Event Foo()

Public ReadOnly Property NumberOfFooHandlers() As Integer
Get
Return FooEvent.GetInvocationList().Length
End Get
End Property

Public Sub AddSampleHandler()
AddHandler Foo, AddressOf Moo
End Sub

Private Sub Moo()
End Sub
End Class
///

For checking if a method exists:

<http://groups.google.com/groups?selm=#[email protected]>
 
Back
Top