using System;
using System.Reflection;
namespace Reflection
{
class Test
{
protected void methodname()
{
Console.WriteLine(("in the world of the reflection"));
Console.Read();
}
}
class Program
{
static void Main(string[] args)
{
// BindingFlags eFlags = BindingFlags.Default | BindingFlags.Instance | BindingFlags.Public|BindingFlags.NonPublic;
BindingFlags eFlags = BindingFlags.Instance|BindingFlags.NonPublic;
Test aTest = new Test();
MethodInfo mInfoMethod = typeof(Reflection.Test).GetMethod("methodname", eFlags);
mInfoMethod.Invoke(aTest, null);
}
}
}
As per the msdn BindingFlags.Nonpublic is used to access the non private members. If I use only this enum the Getmethod returns null value. But if use the enum – Instance and nonpublic the required method is called. What is the difference between these two. When I have to use instance and public/nonpublic combination.
Per the documentation of
GetMethod():Instance/StaticandPublic/NonPublicspecify two different things and you have to specify both in order to get the result.