Type t = typeof(T);
t.GetProperty("Company")
If i write the below code it will give null
Type t = typeof(T);
t.GetProperty("company", BindingFlags.IgnoreCase)
In the mean time if i write this works fine.Why is that so ?
Type t = typeof(T);
t.GetProperty("company", BindingFlags.IgnoreCase|BindingFlags.Public | BindingFlags.Instance)
The search for name is case-sensitive. The search includes public static and public instance properties.
BindingFlags values are used to control binding in methods in classes that find and invoke, create, get, and set members and types. To specify multiple BindingFlags values, use the bitwise 'OR' operator.
The overload which doesn't take BindingFlags
effectively defaults to BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance
. That's why it finds it in your first snippet.
If you do specify a BindingFlags
, you have to specify all the relevant flags - which includes flags to say whether you want to see public members, whether you want to see non-public members, whether you want to see instance members, and whether you want to see static members.
When you just specify BindingFlags.IgnoreCase
, you haven't said you want to see any of those, so it won't find anything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With