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.
abp/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/GlobalFeatureNameAttribute.cs

44 lines
1.1 KiB

using System;
using System.Linq;
using System.Reflection;
using JetBrains.Annotations;
namespace Volo.Abp.GlobalFeatures
{
[AttributeUsage(AttributeTargets.Class)]
public class GlobalFeatureNameAttribute : Attribute
{
[NotNull]
public string Name { get; }
public GlobalFeatureNameAttribute([NotNull] string name)
{
Name = Check.NotNullOrWhiteSpace(name, nameof(name));
}
public static string GetName<TFeature>()
{
return GetName(typeof(TFeature));
}
[NotNull]
public static string GetName([NotNull] Type type)
{
Check.NotNull(type, nameof(type));
var attribute = type
.GetCustomAttributes<GlobalFeatureNameAttribute>()
.FirstOrDefault();
if (attribute == null)
{
throw new AbpException($"{type.AssemblyQualifiedName} should define the {typeof(GlobalFeatureNameAttribute).FullName} atttribute!");
}
return attribute
.As<GlobalFeatureNameAttribute>()
.Name;
}
}
}