Get only local methods of a class with Reflection

  • Thread starter Thread starter Cezar
  • Start date Start date
C

Cezar

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>
 
Cezar said:
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.
 
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
 
Back
Top