reflection and bindingflags

B

billsahiker

How can I use reflection to inspect any assembly and get only the
methods written by the developers of the assembly, not all the built-
in methods. When I use GetMethods on the Module, it returns all the
built-in methods, so for a Form, I get
get_autosize, get_autoscroll, which I do not want. How can I filter
those out? I tried bindingflags,
but any combination of bindingflags returns an empty methodinfo
collection, e.g., "bindingflags.declaredonly or bindingflags.public
or
bindingflags.nonpublic."
Using framework 2.0 and vs2005.

Bill
 
N

Nicholas Paldino [.NET/C# MVP]

Bill,

Well, there is no such thing as a "built-in" method or property. Also,
the compiler doesn't know what you wrote vs something someone else wrote.

However, you are on the right track to get what you want. I imagine
that you are using ONLY the DeclaredOnly flag, when you need to declare the
Public and/or NonPublic flag, as well as the Static and/or Instance flag as
well. I think you are missing one of these.

Can you show the code you are using?
 
B

billsahiker

What I meant by built-in methods is that GetMethods with no
paramenters returns 493 methods for type Form1 that are not in my
source code. They appear to be all of Visual Studio's internal methods
for a standard Windows Form, like get_autosize and ValidateChildren. I
do use the DeclaredOnly bindings flag in conjunction with other flags,
as in "bindingflags.declaredonly or bindingflags.public or
bindingflags.nonpublic." My development machine is new and no
internet access until I get the firewall and anti-virus stuff set up,
so cannot supply the code without manually typing it.

Bill


Bill,

Well, there is no such thing as a "built-in" method or property. Also,
the compiler doesn't know what you wrote vs something someone else wrote.

However, you are on the right track to get what you want. I imagine
that you are using ONLY the DeclaredOnly flag, when you need to declare the
Public and/or NonPublic flag, as well as the Static and/or Instance flag as
well. I think you are missing one of these.

Can you show the code you are using?

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




How can I use reflection to inspect any assembly and get only the
methods written by the developers of the assembly, not all the built-
in methods. When I use GetMethods on the Module, it returns all the
built-in methods, so for a Form, I get
get_autosize, get_autoscroll, which I do not want. How can I filter
those out? I tried bindingflags,
but any combination of bindingflags returns an empty methodinfo
collection, e.g., "bindingflags.declaredonly or bindingflags.public
or
bindingflags.nonpublic."
Using framework 2.0 and vs2005.
Bill- Hide quoted text -

- Show quoted text -
 

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