UnitOfWorkDefaultOptionsExtensions.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Linq;
  3. using System.Reflection;
  4. namespace Abp.Domain.Uow
  5. {
  6. internal static class UnitOfWorkDefaultOptionsExtensions
  7. {
  8. public static UnitOfWorkAttribute GetUnitOfWorkAttributeOrNull(this IUnitOfWorkDefaultOptions unitOfWorkDefaultOptions, MethodInfo methodInfo)
  9. {
  10. var attrs = methodInfo.GetCustomAttributes(true).OfType<UnitOfWorkAttribute>().ToArray();
  11. if (attrs.Length > 0)
  12. {
  13. return attrs[0];
  14. }
  15. attrs = methodInfo.DeclaringType.GetTypeInfo().GetCustomAttributes(true).OfType<UnitOfWorkAttribute>().ToArray();
  16. if (attrs.Length > 0)
  17. {
  18. return attrs[0];
  19. }
  20. if (unitOfWorkDefaultOptions.IsConventionalUowClass(methodInfo.DeclaringType))
  21. {
  22. return new UnitOfWorkAttribute(); //Default
  23. }
  24. return null;
  25. }
  26. public static bool IsConventionalUowClass(this IUnitOfWorkDefaultOptions unitOfWorkDefaultOptions, Type type)
  27. {
  28. return unitOfWorkDefaultOptions.ConventionalUowSelectors.Any(selector => selector(type));
  29. }
  30. }
  31. }