You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.1 KiB

2 years ago
  1. using System;
  2. using System.Reflection;
  3. namespace SqlSugar
  4. {
  5. public static class ReflectionExtensions
  6. {
  7. public static Type GetTypeInfo(this Type typeInfo)
  8. {
  9. return typeInfo;
  10. }
  11. public static Type[] GetGenericArguments(this Type type)
  12. {
  13. var reval = type.GetTypeInfo().GetGenericArguments();
  14. return reval;
  15. }
  16. public static bool IsGenericType(this Type type)
  17. {
  18. var reval = type.GetTypeInfo().IsGenericType;
  19. return reval;
  20. }
  21. public static PropertyInfo[] GetProperties(this Type type)
  22. {
  23. var reval = type.GetTypeInfo().GetProperties();
  24. return reval;
  25. }
  26. public static PropertyInfo GetProperty(this Type type, string name)
  27. {
  28. var reval = type.GetTypeInfo().GetProperty(name);
  29. return reval;
  30. }
  31. public static FieldInfo GetField(this Type type, string name)
  32. {
  33. var reval = type.GetTypeInfo().GetField(name);
  34. return reval;
  35. }
  36. public static bool IsEnum(this Type type)
  37. {
  38. var reval = type.GetTypeInfo().IsEnum;
  39. return reval;
  40. }
  41. public static MethodInfo GetMethod(this Type type, string name)
  42. {
  43. var reval = type.GetTypeInfo().GetMethod(name);
  44. return reval;
  45. }
  46. public static MethodInfo GetMethod(this Type type, string name, Type[] types)
  47. {
  48. var reval = type.GetTypeInfo().GetMethod(name, types);
  49. return reval;
  50. }
  51. public static ConstructorInfo GetConstructor(this Type type, Type[] types)
  52. {
  53. var reval = type.GetTypeInfo().GetConstructor(types);
  54. return reval;
  55. }
  56. public static bool IsValueType(this Type type)
  57. {
  58. return type.GetTypeInfo().IsValueType;
  59. }
  60. public static bool IsEntity(this Type type)
  61. {
  62. return type.GetTypeInfo().IsClass;
  63. }
  64. public static Type ReflectedType(this MethodInfo method)
  65. {
  66. return method.ReflectedType;
  67. }
  68. }
  69. }