I am trying to use reflection to call a method on an object and there may be parameters involved. The code works perfectly when no parameters are specified but returns the wrong data when there are parameters.
Here is my code:
object temp = readerTask.GetType().GetProperty(bsplit[0]).GetValue(readerTask, null);
if (useParams)
{
MethodInfo methodInfo = temp.GetType().GetMethod(bsplit[1].Split(new char[] { '(' })[0], new[] { typeof(string) });
string p = bsplit[1].Split(new char[] { '(', ')' })[1];
value = methodInfo.Invoke(temp, new[] { p });
}
else
{
value = temp.GetType().GetMethod(bsplit[1]).Invoke(temp, null);
}
As an example, my input string is Date.ToString("MMMM dd, yyyy")
.
The object temp has the correct date object in it that I want to format, but when I run through the code, the data in the value variable is MMMM dd, yyyy
How can I get the method to run and use the parameters correctly?
Aucun commentaire:
Enregistrer un commentaire