When I try to invoke this it isn't working. Null doesn't work as for other methods that are being called in this fashion, but for this particular one, it's causing problems.
The methods this is attempting to call are static, so I used null. I then tried creating an instance in the manner below, then I attempted removing static from the methods. I have been looking at msdn documentation on method.Invoke() and can't see any other way to do this. And break points are not being hit anywhere inside the methods, so the invocation is failing, not the methods I am trying to invoke
As it is, this is throwing a generic exception, otherwise I would include the details of the error.
//somewhere in code
getLoginInfo.Get("bob", "JobSeeker");
public object Get(string userName, string userType)
{
object data = null;
try
{
using (var db = new dbEntities())
{
ReflectionHelpers rh = new ReflectionHelpers();
data = rh.CallMethodIfExists(new GetLogin(), userType, new object[] { db, userName });
}
}
catch (Exception e)
{
return e;
}
}
public static object JobSeeker(aos_activeEntities aos, string userName)
{
return aos.Logins.Select(login => login.Login1.Equals(userName));
}
//meanwhile
public object CallMethodIfExists(Object obj, string methodName, object[] args)
{
if (HasMethod(obj, methodName))
{
MethodInfo methodInfo = obj.GetType().GetMethod(methodName);
return methodInfo.Invoke(Activator.CreateInstance(obj.GetType()), args);
}
}
Aucun commentaire:
Enregistrer un commentaire