| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using System;
- using System.Reflection;
- using Abp.Reflection.Extensions;
- namespace Abp.Application.Services
- {
- [Serializable]
- [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Method)]
- public class RemoteServiceAttribute : Attribute
- {
- /// <summary>
- /// Default: true.
- /// </summary>
- public bool IsEnabled { get; set; }
- /// <summary>
- /// Default: true.
- /// </summary>
- public bool IsMetadataEnabled { get; set; }
- public RemoteServiceAttribute(bool isEnabled = true)
- {
- IsEnabled = isEnabled;
- IsMetadataEnabled = true;
- }
- public virtual bool IsEnabledFor(Type type)
- {
- return IsEnabled;
- }
- public virtual bool IsEnabledFor(MethodInfo method)
- {
- return IsEnabled;
- }
- public virtual bool IsMetadataEnabledFor(Type type)
- {
- return IsMetadataEnabled;
- }
- public virtual bool IsMetadataEnabledFor(MethodInfo method)
- {
- return IsMetadataEnabled;
- }
- public static bool IsExplicitlyEnabledFor(Type type)
- {
- var remoteServiceAttr = type.GetTypeInfo().GetSingleAttributeOrNull<RemoteServiceAttribute>();
- return remoteServiceAttr != null && remoteServiceAttr.IsEnabledFor(type);
- }
- public static bool IsExplicitlyDisabledFor(Type type)
- {
- var remoteServiceAttr = type.GetTypeInfo().GetSingleAttributeOrNull<RemoteServiceAttribute>();
- return remoteServiceAttr != null && !remoteServiceAttr.IsEnabledFor(type);
- }
- public static bool IsMetadataExplicitlyEnabledFor(Type type)
- {
- var remoteServiceAttr = type.GetTypeInfo().GetSingleAttributeOrNull<RemoteServiceAttribute>();
- return remoteServiceAttr != null && remoteServiceAttr.IsMetadataEnabledFor(type);
- }
- public static bool IsMetadataExplicitlyDisabledFor(Type type)
- {
- var remoteServiceAttr = type.GetTypeInfo().GetSingleAttributeOrNull<RemoteServiceAttribute>();
- return remoteServiceAttr != null && !remoteServiceAttr.IsMetadataEnabledFor(type);
- }
- public static bool IsMetadataExplicitlyDisabledFor(MethodInfo method)
- {
- var remoteServiceAttr = method.GetSingleAttributeOrNull<RemoteServiceAttribute>();
- return remoteServiceAttr != null && !remoteServiceAttr.IsMetadataEnabledFor(method);
- }
- public static bool IsMetadataExplicitlyEnabledFor(MethodInfo method)
- {
- var remoteServiceAttr = method.GetSingleAttributeOrNull<RemoteServiceAttribute>();
- return remoteServiceAttr != null && remoteServiceAttr.IsMetadataEnabledFor(method);
- }
- }
- }
|