gpt4 book ai didi

c# - 不区分大小写的 GetMethod?

转载 作者:可可西里 更新时间:2023-11-01 07:51:24 25 4
gpt4 key购买 nike

foreach(var filter in filters)
{
var filterType = typeof(Filters);
var method = filterType.GetMethod(filter);
if (method != null) value = (string)method.Invoke(null, new[] { value });
}

获取方法有没有不区分大小写的方法?

最佳答案

是的,使用 BindingFlags.IgnoreCase:

var method = filterType.GetMethod(filter, 
BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);

当心可能的歧义,你会得到一个 AmbiguousMatchException。

关于c# - 不区分大小写的 GetMethod?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4010003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com