RemoteServiceAttribute.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Reflection;
  3. using Abp.Reflection.Extensions;
  4. namespace Abp.Application.Services
  5. {
  6. [Serializable]
  7. [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Method)]
  8. public class RemoteServiceAttribute : Attribute
  9. {
  10. /// <summary>
  11. /// Default: true.
  12. /// </summary>
  13. public bool IsEnabled { get; set; }
  14. /// <summary>
  15. /// Default: true.
  16. /// </summary>
  17. public bool IsMetadataEnabled { get; set; }
  18. public RemoteServiceAttribute(bool isEnabled = true)
  19. {
  20. IsEnabled = isEnabled;
  21. IsMetadataEnabled = true;
  22. }
  23. public virtual bool IsEnabledFor(Type type)
  24. {
  25. return IsEnabled;
  26. }
  27. public virtual bool IsEnabledFor(MethodInfo method)
  28. {
  29. return IsEnabled;
  30. }
  31. public virtual bool IsMetadataEnabledFor(Type type)
  32. {
  33. return IsMetadataEnabled;
  34. }
  35. public virtual bool IsMetadataEnabledFor(MethodInfo method)
  36. {
  37. return IsMetadataEnabled;
  38. }
  39. public static bool IsExplicitlyEnabledFor(Type type)
  40. {
  41. var remoteServiceAttr = type.GetTypeInfo().GetSingleAttributeOrNull<RemoteServiceAttribute>();
  42. return remoteServiceAttr != null && remoteServiceAttr.IsEnabledFor(type);
  43. }
  44. public static bool IsExplicitlyDisabledFor(Type type)
  45. {
  46. var remoteServiceAttr = type.GetTypeInfo().GetSingleAttributeOrNull<RemoteServiceAttribute>();
  47. return remoteServiceAttr != null && !remoteServiceAttr.IsEnabledFor(type);
  48. }
  49. public static bool IsMetadataExplicitlyEnabledFor(Type type)
  50. {
  51. var remoteServiceAttr = type.GetTypeInfo().GetSingleAttributeOrNull<RemoteServiceAttribute>();
  52. return remoteServiceAttr != null && remoteServiceAttr.IsMetadataEnabledFor(type);
  53. }
  54. public static bool IsMetadataExplicitlyDisabledFor(Type type)
  55. {
  56. var remoteServiceAttr = type.GetTypeInfo().GetSingleAttributeOrNull<RemoteServiceAttribute>();
  57. return remoteServiceAttr != null && !remoteServiceAttr.IsMetadataEnabledFor(type);
  58. }
  59. public static bool IsMetadataExplicitlyDisabledFor(MethodInfo method)
  60. {
  61. var remoteServiceAttr = method.GetSingleAttributeOrNull<RemoteServiceAttribute>();
  62. return remoteServiceAttr != null && !remoteServiceAttr.IsMetadataEnabledFor(method);
  63. }
  64. public static bool IsMetadataExplicitlyEnabledFor(MethodInfo method)
  65. {
  66. var remoteServiceAttr = method.GetSingleAttributeOrNull<RemoteServiceAttribute>();
  67. return remoteServiceAttr != null && remoteServiceAttr.IsMetadataEnabledFor(method);
  68. }
  69. }
  70. }