66 lines
2.0 KiB
C#
66 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
|
|
namespace NBF
|
|
{
|
|
public static class AttributeHelper
|
|
{
|
|
// 获取特定嵌套类中带有InputIconAttribute的常量字段
|
|
public static Dictionary<string, List<FieldInfo>> GetNestedClassInputIconFields()
|
|
{
|
|
var result = new Dictionary<string, List<FieldInfo>>();
|
|
|
|
// 获取InputDef类型
|
|
Type inputDefType = typeof(NBF.InputDef);
|
|
|
|
// 检查UI类
|
|
Type uiType = inputDefType.GetNestedType("UI");
|
|
if (uiType != null)
|
|
{
|
|
var uiFields = GetInputIconFieldsFromType(uiType);
|
|
if (uiFields.Count > 0)
|
|
{
|
|
result.Add("UI", uiFields);
|
|
}
|
|
}
|
|
|
|
// 检查Player类
|
|
Type playerType = inputDefType.GetNestedType("Player");
|
|
if (playerType != null)
|
|
{
|
|
var playerFields = GetInputIconFieldsFromType(playerType);
|
|
if (playerFields.Count > 0)
|
|
{
|
|
result.Add("Player", playerFields);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
// 从特定类型获取带有InputIconAttribute的常量字段
|
|
private static List<FieldInfo> GetInputIconFieldsFromType(Type type)
|
|
{
|
|
List<FieldInfo> result = new List<FieldInfo>();
|
|
|
|
// 只获取公共常量字段
|
|
FieldInfo[] fields = type.GetFields(
|
|
BindingFlags.Public |
|
|
BindingFlags.Static |
|
|
BindingFlags.FlattenHierarchy);
|
|
|
|
foreach (FieldInfo field in fields)
|
|
{
|
|
// 检查是否是常量且带有InputIconAttribute
|
|
if (field.IsLiteral && !field.IsInitOnly &&
|
|
Attribute.IsDefined(field, typeof(InputIconAttribute)))
|
|
{
|
|
result.Add(field);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
} |