Answer the question
In order to leave comments, you need to log in
How to get an overloaded method using reflection, where one of the parameters is ref or out?
Situation. It is necessary to call TryParse using reflection (for example, Double)
But there are two problems, TryParse is an overloaded method. and secondly, I specifically need
TryParse(string, out double)
In theory, this code should work:
var modefier = new ParameterModifier(2);
modefier[0] = false;
modefier[1] = true;
MethodInfo mi1 =
typeof(Double).GetMethod("TryParse", new Type[]{typeof(string), typeof(Double)}, new ParameterModifier[]{modefier});
Answer the question
In order to leave comments, you need to log in
MethodInfo mi1 = typeof(Double).GetMethod("TryParse",
BindingFlags.Static | BindingFlags.Public,
null,
new Type[] { typeof(string), typeof(Double).MakeByRefType() },
null);
MethodInfo TryParseDouble = typeof(double).GetMethod("TryParse",
BindingFlags.Public | BindingFlags.Static,
null,
CallingConventions.Any,
new[] { typeof(string), typeof(double).MakeByRefType() },
null);
object[] parameters = {"1818,1818", 0.0 };
double rezult;
if ((bool)TryParseDouble.Invoke(null, parameters))
{
rezult = (double)parameters[1];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question