Guest User

Untitled

a guest
Feb 16th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. public static object GetUnicornFied(this object obj, string fieldName)
  2. {
  3. return obj.GetUnicornFied(fieldName, obj.GetType(), true);
  4. }
  5. public static object GetUnicornFied(this object obj, string fieldName, Type type, bool recursive)
  6. {
  7. object result;
  8. try
  9. {
  10.  
  11. BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
  12. bool flag = type != null;
  13. if (flag)
  14. {
  15. FieldInfo field = type.GetUnicorn(fieldName, bindingAttr);
  16. bool flag2 = field != null;
  17. if (flag2)
  18. {
  19. result = field.GetValue(obj);
  20. return result;
  21. }
  22. bool flag3 = recursive && type.BaseType != null;
  23. if (flag3)
  24. {
  25. result = obj.GetUnicornFied(fieldName, type.BaseType, true);
  26. return result;
  27. }
  28. }
  29. }
  30. catch
  31. {
  32. }
  33. result = null;
  34. return result;
  35. }
  36. // Instance Specifies that static members are to be included in the search, line 11
  37. // Non Public Specifies that public and protected static members up the hierarchy should be returned.
  38. //Private static members in inherited classes are not returned.
Add Comment
Please, Sign In to add comment