dim fooDelegate as Class1.Foo
dim barDelegate as Class1.Bar
fooDelegate=new Class1.Foo(AddressOf NoParamMethod)
barDelegate=new Class1.Bar(AddressOf NoParamMethod)
if fooDelegate isa Class1.Foo then
break
end
if fooDelegate isa Class1.Bar then
break
end
Foo and Bar are Delegates in Class1, both with no parameters. NoParamMethod is a method on Class1 with no parameters. When this code is run, both breaks are hit.
If I change the method signatures of either delegate; for example, if I add an integer parameter to the Foo delegate; then only the first break is hit. This suggests that the IsA operator is considering the method signature.
This strikes me as odd behavior. Delegates sure look and behave like single-method class interfaces, but class interfaces never compare like this. Shouldn’t Delegates with the same signature still be distinct? As it stands, there’s no way to distinguish between two Delegate objects with identical signatures.
In my use case, I was thinking about having multiple Delegates in a dictionary and using their “class” via IsA to determine how to handle them (for example, one Delegate might have an integer parameter that indicates width, while another might have an integer parameter that indicates height).
dim fooDelegate as Class1.Foo
dim barDelegate as Class1.Bar
fooDelegate=new Class1.Foo(AddressOf NoParamMethod)
barDelegate=new Class1.Bar(AddressOf NoParamMethod2)
if fooDelegate isa Class1.Foo then
break
end
if fooDelegate isa Class1.Bar then
break
end
They are confusing because you’re using it wrong. A Delegate is intended to completely decouple from the method being called. As long as the parameters match, it could point to any method at all. There is no way to get the identity of that method; it isn’t intended to.
I’m not trying to get the identity of the method the Delegate points to. I’m trying to get at which delegate definition the Delegate is based on - Foo or Bar.
I don’t see any way to do this at present, which seems odd.