MethodInfo.Invoke与out参数

我试图做的一个示例代码肯定会比我的英语做得更好:

public bool IsNumericValueInBounds (string value, Type numericType) { double d = double.NaN; bool inBounds = (bool)numericType.GetMethod ("TryParse").Invoke (null, new object[] { value, d }); return inBounds; } 

不幸的是TryParse方法需要一个out参数,所以这是行不通的。 任何想法如何解决这个问题?

(ps .:这不是一个很好的鸭子打字的例子吗? – 因为我知道每个numericType都有一个“TryParse”,或者我误会了)

 public static bool TryParse( string text, out int number ) { .. } MethodInfo method = GetTryParseMethodInfo(); object[] parameters = new object[]{ "12345", null } object result = method.Invoke( null, parameters ); bool blResult = (bool)result; if ( blResult ) { int parsedNumber = (int)parameters[1]; }