lundi 12 janvier 2015

GetRuntimeProperties instead of GetProperty

I need to find property inside of generic type. This is an old way (and since my code is dedicated for WinRT I believe I need another approach):



PropertyInfo pi = typeof(TRp).GenericTypeArguments[0].GetProperty(idField, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);


I need to achieve the same result using GetRuntimeProperties. This is my approach:



PropertyInfo pi = typeof(TRp).GenericTypeArguments[0].GetRuntimeProperties().Single(p => p.Name.ToUpper() == idField.ToUpper()...


as you can see I implemented IgnoreCase in a custom way, probably it can be done better?

How can I implement remaining BindingFlags?


Thank you!






Aucun commentaire:

Enregistrer un commentaire