Reflection.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. #if CRIPPLED_REFLECTION
  5. using System.Linq;
  6. using System.Reflection;
  7. namespace System.Reflection
  8. {
  9. [Flags]
  10. internal enum BindingFlags
  11. {
  12. Instance = 4,
  13. Static = 8,
  14. Public = 16,
  15. NonPublic = 32,
  16. }
  17. }
  18. namespace System
  19. {
  20. static class TypeExtensions
  21. {
  22. public static bool IsAssignableFrom(this Type t1, Type t2)
  23. {
  24. return t1.GetTypeInfo().IsAssignableFrom(t2.GetTypeInfo());
  25. }
  26. public static MethodInfo[] GetMethods(this Type t, BindingFlags flags)
  27. {
  28. return t.GetTypeInfo().DeclaredMethods.Where(m => IsVisible(m, flags)).ToArray();
  29. }
  30. private static bool IsVisible(MethodInfo method, BindingFlags flags)
  31. {
  32. if ((flags & BindingFlags.Public) != 0 != method.IsPublic)
  33. {
  34. return false;
  35. }
  36. if ((flags & BindingFlags.NonPublic) == 0 && !method.IsPublic)
  37. {
  38. return false;
  39. }
  40. if ((flags & BindingFlags.Static) != 0 != method.IsStatic)
  41. {
  42. return false;
  43. }
  44. return true;
  45. }
  46. }
  47. }
  48. #endif