设置相关功能脚本呢

This commit is contained in:
bob
2025-05-30 17:49:12 +08:00
parent e9ad74b3ea
commit dea58270fa
62 changed files with 1164 additions and 476 deletions

View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using NBF.Setting;
namespace NBF
{
public static class ListExtends
{
public static void SortBySortAttribute(this List<OptionBase> list)
{
if (list == null)
throw new ArgumentNullException(nameof(list));
list.Sort((a, b) =>
{
var orderA = GetSortOrder(a);
var orderB = GetSortOrder(b);
return orderA.CompareTo(orderB);
});
}
private static int GetSortOrder(OptionBase option)
{
if (option == null)
return 999;
var sortAttribute = option.GetType()
.GetCustomAttribute<SortAttribute>(inherit: false);
return sortAttribute?.Sort ?? 999;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 87135425aeb24b8ead2f411dceabb955
timeCreated: 1748591603