BindingFlags.IgnoreCase not working for Type.GetProperty()?

Boris Callens picture Boris Callens · Nov 5, 2008 · Viewed 36.7k times · Source

Imagine the following

A type T has a field Company. When executing the following method it works perfectly:

Type t = typeof(T);
t.GetProperty("Company")

Whith the following call I get null though

Type t = typeof(T);
t.GetProperty("company", BindingFlags.IgnoreCase)

Anybody got an idea?

Answer

Pop Catalin picture Pop Catalin · Nov 5, 2008

You've overwritten the default look-up flags, if you specify new flags you need to provide all the info so that the property can be found. For example: BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance