473,394 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Get only local methods of a class with Reflection

Hi,

Does anyone know how to get the list of local declared method
of a class using Reflection.
I didn't see a flag like %IsLocal% for MethodInfo...

The code I use now returns all method, locally declared and inherited

<snip>
MethodInfo [] methodsInfo = cl.GetMethods();
foreach(MethodInfo mi in methodsInfo)
{
if (!MethodsHash.ContainsKey(mi.ToString() ))
{
MethodsList.Add(mi.ToString(), "method");
MethodsHash.Add(mi.ToString(),"");
}
}
</snip>
Nov 15 '05 #1
2 2360
Cezar <ce*********@polymtl.ca> wrote:
Does anyone know how to get the list of local declared method
of a class using Reflection.
I didn't see a flag like %IsLocal% for MethodInfo...

The code I use now returns all method, locally declared and inherited

<snip>
MethodInfo [] methodsInfo = cl.GetMethods();
foreach(MethodInfo mi in methodsInfo)
{
if (!MethodsHash.ContainsKey(mi.ToString() ))
{
MethodsList.Add(mi.ToString(), "method");
MethodsHash.Add(mi.ToString(),"");
}
}


Use the version of Type.GetMethods which takes a BindingFlags
parameter, and use BindingFlags.DeclaredOnly as one of the flags.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
> Use the version of Type.GetMethods which takes a BindingFlags
parameter, and use BindingFlags.DeclaredOnly as one of the flags.


Excellent, thank you.

I've been a bit fooled by the fact you have to specify all the flags
for the type you want (Public / NonPublic etc) if not it doesn't
return a thing.

Thanks again Jon

Cezar
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Fernando Rodriguez | last post by:
Hi, I have a base class with a 'sanity-check' method. This method should iterate through all the methods and check if they are all 'thunks' (zero parameter functions, well actually, 1 parameter:...
1
by: Daniel | last post by:
how do i access methods when the .net assembly was loaded with late biding? class Class1 { public static void Main() { System.Reflection.Assembly SampleAssembly; SampleAssembly =...
0
by: Paul Lyons | last post by:
Hi, I've been having an issue using reflection and custom attributes to create objects on the fly. I was wondering if this was expected behaviour or a known bug? When using Type.GetMembers()...
42
by: Stefan | last post by:
Could someone please explain if there is a difference between when one should use the word method or function. Do they have the same meaning?
2
by: Don | last post by:
Is it possible to call a shared method of a class when you have both the name of the class and the name of the method of that class that you want to invoke stored in strings? If so, can this be...
15
by: Jeff Mason | last post by:
Hi, I'm having a reflection brain fog here, perhaps someone can set me on the right track. I'd like to define a custom attribute to be used in a class hierarchy. What I want to do is to...
4
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I have a user control that is designed as below. I am creating these User Controls Dynamically in another form. They are multiple types of User Controls all with a common Interface so I can...
0
by: csharpuser | last post by:
Does anybody know how to disallow the direct invokation of a private method using reflection but still allow the invokation through reflection of a public method which uses the private method. To...
3
by: johanatan | last post by:
When I first heard about these new features, I was very excited as it would have (if implemented as I had expected) rendered mimicking multiple inheritance almost painless in C#. Unfortunately,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.