我尝试做的示例代码肯定会比我的英文做得更好:
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"或者我错了?)
TcK*_*cKs 120
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];
}
| 归档时间: | 
 | 
| 查看次数: | 26021 次 | 
| 最近记录: |