Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case-insensitive GetMethod?

Tags:

c#

reflection

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?

like image 609
mpen Avatar asked Oct 24 '10 19:10

mpen


1 Answers

Yes, use BindingFlags.IgnoreCase:

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

Beware the possible ambiguity, you'd get an AmbiguousMatchException.

like image 147
Hans Passant Avatar answered Oct 13 '22 15:10

Hans Passant