I'm using a public static class and static method with its parameters:
public static class WLR3Logon
{
static void getLogon(int accountTypeID)
{}
}
Now I am trying to fetch the method with its parameters into another class and using the following code:
MethodInfo inf = typeof(WLR3Logon).GetMethod("getLogon",
BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
int[] parameters = { accountTypeId };
foreach (int parameter in parameters)
{
inf.Invoke("getLogon", parameters);
}
But its giving me error
"Object reference not set to an instance of an object."
Where I'm going wrong.
This problem got solved by using the following approach:
using System.Reflection;
string methodName = "getLogon";
Type type = typeof(WLR3Logon);
MethodInfo info = type.GetMethod(
methodName,
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
object value = info.Invoke(null, new object[] { accountTypeId } );
There are many problems here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With