相关疑难解决方法(0)

将变量转换为仅在运行时已知的类型?

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 });
    }
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能投valueparamTypevaluestring,paramType很可能只是一个基本的类型一样int,string或者可能float.如果没有可能的转换,我会很好地抛出异常.

c#

75
推荐指数
2
解决办法
7万
查看次数

标签 统计

c# ×1