ReflectionExtensions.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #if NETSTANDARD1_3
  2. using System;
  3. using System.Linq;
  4. using System.Reflection;
  5. namespace Jint
  6. {
  7. internal static class ReflectionExtensions
  8. {
  9. internal static bool IsEnum(this Type type)
  10. {
  11. return type.GetTypeInfo().IsEnum;
  12. }
  13. internal static bool IsGenericType(this Type type)
  14. {
  15. return type.GetTypeInfo().IsGenericType;
  16. }
  17. internal static bool IsValueType(this Type type)
  18. {
  19. return type.GetTypeInfo().IsValueType;
  20. }
  21. internal static bool HasAttribute<T>(this ParameterInfo member) where T : Attribute
  22. {
  23. return member.GetCustomAttributes<T>().Any();
  24. }
  25. }
  26. }
  27. #else
  28. using System;
  29. using System.Reflection;
  30. namespace Jint
  31. {
  32. internal static class ReflectionExtensions
  33. {
  34. internal static bool IsEnum(this Type type)
  35. {
  36. return type.IsEnum;
  37. }
  38. internal static bool IsGenericType(this Type type)
  39. {
  40. return type.IsGenericType;
  41. }
  42. internal static bool IsValueType(this Type type)
  43. {
  44. return type.IsValueType;
  45. }
  46. internal static bool HasAttribute<T>(this ParameterInfo member) where T : Attribute
  47. {
  48. return Attribute.IsDefined(member, typeof(T));
  49. }
  50. internal static MethodInfo GetMethodInfo(this Delegate d)
  51. {
  52. return d.Method;
  53. }
  54. }
  55. }
  56. #endif