1
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
@@ -57,6 +58,29 @@ namespace BITKit
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
|
||||
public class ExportAttribute : System.Attribute
|
||||
{
|
||||
public static string GetName(object obj)
|
||||
{
|
||||
var att = obj.GetType().GetCustomAttribute<ExportAttribute>();
|
||||
att = obj switch
|
||||
{
|
||||
FieldInfo field => field.GetCustomAttribute<ExportAttribute>(),
|
||||
MethodInfo method => method.GetCustomAttribute<ExportAttribute>(),
|
||||
PropertyInfo property => property.GetCustomAttribute<ExportAttribute>(),
|
||||
_ => att
|
||||
};
|
||||
if (att is null) return obj.GetType().Name;
|
||||
if (string.IsNullOrEmpty(att.Name))
|
||||
{
|
||||
return obj switch
|
||||
{
|
||||
FieldInfo field => field.Name,
|
||||
MethodInfo method => method.Name,
|
||||
PropertyInfo property => property.Name,
|
||||
_ => att.Name
|
||||
};
|
||||
}
|
||||
return att.Name;
|
||||
}
|
||||
public readonly string Name;
|
||||
public readonly IExportSetting Settings;
|
||||
public ExportAttribute(){}
|
||||
|
Reference in New Issue
Block a user