Reflection.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
  2. #if CRIPPLED_REFLECTION
  3. using System.Linq;
  4. using System.Reflection;
  5. namespace System.Reflection
  6. {
  7. [Flags]
  8. internal enum BindingFlags
  9. {
  10. Instance = 4,
  11. Static = 8,
  12. Public = 16,
  13. NonPublic = 32,
  14. }
  15. }
  16. namespace System
  17. {
  18. static class TypeExtensions
  19. {
  20. public static bool IsAssignableFrom(this Type t1, Type t2)
  21. {
  22. return t1.GetTypeInfo().IsAssignableFrom(t2.GetTypeInfo());
  23. }
  24. public static MethodInfo[] GetMethods(this Type t, BindingFlags flags)
  25. {
  26. return t.GetTypeInfo().DeclaredMethods.Where(m => IsVisible(m, flags)).ToArray();
  27. }
  28. private static bool IsVisible(MethodInfo method, BindingFlags flags)
  29. {
  30. if ((flags & BindingFlags.Public) != 0 != method.IsPublic)
  31. {
  32. return false;
  33. }
  34. if ((flags & BindingFlags.NonPublic) == 0 && !method.IsPublic)
  35. {
  36. return false;
  37. }
  38. if ((flags & BindingFlags.Static) != 0 != method.IsStatic)
  39. {
  40. return false;
  41. }
  42. return true;
  43. }
  44. }
  45. }
  46. #endif