foreach (var filter in filters)
{
var filterType = typeof(Filters);
var method = filterType.GetMethod(filter, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Static);
if (method != null)
{
var parameters = method.GetParameters();
Type paramType = parameters[0].ParameterType;
value = (string)method.Invoke(null, new[] { value });
}
}
我该如何投value
到paramType
? value
是string
,paramType
可能只是基本类型,如int
,string
或者可能float
。如果没有可能的转换,我很酷并抛出异常。将变量转换为仅在运行时已知的类型?
可能重复的[?如何查找和调用的.Net的TypeConverter用于特定类型](http://stackoverflow.com/questions/956076/how-to-lookup-and-invoke -a-net-typeconverter-for-a-specific-type) – 2010-10-24 20:05:40
可能出现[如何查找和调用特定类型的.Net TypeConverter?](http://stackoverflow.com/questions/956076/how-查找和调用一个特定类型的网络类型转换器) – 2017-03-16 10:18:20