不区分大小写GetMethod? [英] Case-insensitive GetMethod?
本文介绍了不区分大小写GetMethod?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
foreach(var filter in filters)
{
var filterType = typeof(Filters);
var method = filterType.GetMethod(filter);
if (method != null) value = (string)method.Invoke(null, new[] { value });
}
有一个不区分大小写的方式来获得的方法?
Is there a case-insensitive way to get a method?
推荐答案
是,使用BindingFlags.IgnoreCase:
Yes, use BindingFlags.IgnoreCase:
var method = filterType.GetMethod(filter,
BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
谨防可能的暧昧,你会得到一个AmbiguousMatchException。
Beware the possible ambiguity, you'd get an AmbiguousMatchException.
这篇关于不区分大小写GetMethod?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文