code_junkie

How do I use .Net reflection to search for a property by name ignoring case?

Nov 12th, 2011
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. var prop = Backend.GetType().GetProperty(fieldName);
  2.  
  3. var prop = Backend.GetType().GetProperty(fieldName, BindingFlags.IgnoreCase);
  4.  
  5. using System;
  6. using System.Reflection;
  7.  
  8. public class Test
  9. {
  10. private int foo;
  11.  
  12. public int Foo { get { return foo; } }
  13.  
  14. static void Main()
  15. {
  16. var prop = typeof(Test).GetProperty("foo",
  17. BindingFlags.Public
  18. | BindingFlags.Instance
  19. | BindingFlags.IgnoreCase);
  20. Console.WriteLine(prop);
  21. }
  22. }
  23.  
  24. var prop = Backend.GetType().GetProperty(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
Add Comment
Please, Sign In to add comment