Reflection: Distinguishing property from WithEvents field

H

herbert

Using reflection I need to find all (private and public) fields, defined with
the keyword WithEvents.

Those fields are reflected as properties, which makes me ask how to
distinguish between
Public Property X () As myClass and
Public WithEvents X As myClass

thank you very much. herbert
 
F

Family Tree Mike

herbert said:
Using reflection I need to find all (private and public) fields, defined
with
the keyword WithEvents.

Those fields are reflected as properties, which makes me ask how to
distinguish between
Public Property X () As myClass and
Public WithEvents X As myClass

thank you very much. herbert


Well, don't you get an error compiling a class that has the above code? I
get: 'X' is already declared as 'Public Property X() as myClass'.

Aside from that, GetEvents works on the type. You can test which property
names are events.
 
A

Armin Zingler

herbert said:
Using reflection I need to find all (private and public) fields,
defined with the keyword WithEvents.

Those fields are reflected as properties, which makes me ask how to
distinguish between
Public Property X () As myClass and
Public WithEvents X As myClass

thank you very much. herbert

I think it's not 100% reliably possible. 5 can be the result of 4+1 or 3+2.
I mean, the code VB produces by using Withevents could also be written
manually without using Withevents. You could look for a field named "_X" in
this case. If it's there, it _could_ be a WithEvents "variable" - or your
own code. Moreover, this is implementation detail and could change in a
newer version. I've looked for an attribute the VB compiler might attach,
but nope...


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top