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
{
///
/// Default: true.
///
public bool IsEnabled { get; set; }
///
/// Default: true.
///
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();
return remoteServiceAttr != null && remoteServiceAttr.IsEnabledFor(type);
}
public static bool IsExplicitlyDisabledFor(Type type)
{
var remoteServiceAttr = type.GetTypeInfo().GetSingleAttributeOrNull();
return remoteServiceAttr != null && !remoteServiceAttr.IsEnabledFor(type);
}
public static bool IsMetadataExplicitlyEnabledFor(Type type)
{
var remoteServiceAttr = type.GetTypeInfo().GetSingleAttributeOrNull();
return remoteServiceAttr != null && remoteServiceAttr.IsMetadataEnabledFor(type);
}
public static bool IsMetadataExplicitlyDisabledFor(Type type)
{
var remoteServiceAttr = type.GetTypeInfo().GetSingleAttributeOrNull();
return remoteServiceAttr != null && !remoteServiceAttr.IsMetadataEnabledFor(type);
}
public static bool IsMetadataExplicitlyDisabledFor(MethodInfo method)
{
var remoteServiceAttr = method.GetSingleAttributeOrNull();
return remoteServiceAttr != null && !remoteServiceAttr.IsMetadataEnabledFor(method);
}
public static bool IsMetadataExplicitlyEnabledFor(MethodInfo method)
{
var remoteServiceAttr = method.GetSingleAttributeOrNull();
return remoteServiceAttr != null && remoteServiceAttr.IsMetadataEnabledFor(method);
}
}
}