This commit is contained in:
CortexCore
2024-07-17 17:06:45 +08:00
parent e686eb89ab
commit c80a4a2245
7 changed files with 415 additions and 86 deletions

View File

@@ -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(){}