😎1、优化枚举扩展类 2、升级npm依赖
This commit is contained in:
parent
d7351aa5dd
commit
01b4a4519b
@ -31,7 +31,7 @@ public static class EnumExtension
|
||||
throw new ArgumentException("Type '" + enumType.Name + "' is not an enum.");
|
||||
|
||||
// 查询缓存
|
||||
var enumDic = EnumNameValueDict.ContainsKey(enumType) ? EnumNameValueDict[enumType] : new Dictionary<int, string>();
|
||||
var enumDic = EnumNameValueDict.TryGetValue(enumType, out var value) ? value : new Dictionary<int, string>();
|
||||
if (enumDic.Count != 0)
|
||||
return enumDic;
|
||||
// 取枚举类型的Key/Value字典集合
|
||||
@ -57,7 +57,7 @@ public static class EnumExtension
|
||||
// 遍历字段数组获取key和name
|
||||
foreach (var enumField in enumFields)
|
||||
{
|
||||
var intValue = (int)enumField.GetValue(enumType);
|
||||
var intValue = (int)enumField.GetValue(enumType)!;
|
||||
enumDic[intValue] = enumField.Name;
|
||||
}
|
||||
|
||||
@ -76,8 +76,8 @@ public static class EnumExtension
|
||||
throw new ArgumentException("Type '" + enumType.Name + "' is not an enum.");
|
||||
|
||||
// 查询缓存
|
||||
var enumDic = EnumDisplayValueDict.ContainsKey(enumType)
|
||||
? EnumDisplayValueDict[enumType]
|
||||
var enumDic = EnumDisplayValueDict.TryGetValue(enumType, out var value)
|
||||
? value
|
||||
: new Dictionary<int, string>();
|
||||
if (enumDic.Count != 0)
|
||||
return enumDic;
|
||||
@ -105,7 +105,7 @@ public static class EnumExtension
|
||||
// 遍历字段数组获取key和name
|
||||
foreach (var enumField in enumFields)
|
||||
{
|
||||
var intValue = (int)enumField.GetValue(enumType);
|
||||
var intValue = (int)enumField.GetValue(enumType)!;
|
||||
var desc = enumField.GetDescriptionValue<DescriptionAttribute>();
|
||||
enumDic[intValue] = desc != null && !string.IsNullOrEmpty(desc.Description) ? desc.Description : enumField.Name;
|
||||
}
|
||||
@ -125,7 +125,7 @@ public static class EnumExtension
|
||||
_enumTypeDict ??= LoadEnumTypeDict(assembly);
|
||||
|
||||
// 按名称查找
|
||||
return _enumTypeDict.ContainsKey(typeName) ? _enumTypeDict[typeName] : null;
|
||||
return _enumTypeDict.TryGetValue(typeName, out var value) ? value : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -149,10 +149,9 @@ public static class EnumExtension
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetDescription(this System.Enum value)
|
||||
public static string GetDescription(this Enum value)
|
||||
{
|
||||
return value.GetType().GetMember(value.ToString()).FirstOrDefault()?.GetCustomAttribute<DescriptionAttribute>()
|
||||
?.Description;
|
||||
return value.GetType().GetField(value.ToString())?.GetCustomAttribute<DescriptionAttribute>()?.Description;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -162,8 +161,7 @@ public static class EnumExtension
|
||||
/// <returns></returns>
|
||||
public static string GetDescription(this object value)
|
||||
{
|
||||
return value.GetType().GetMember(value.ToString() ?? string.Empty).FirstOrDefault()
|
||||
?.GetCustomAttribute<DescriptionAttribute>()?.Description;
|
||||
return value.GetType().GetField(value.ToString()!)?.GetCustomAttribute<DescriptionAttribute>()?.Description;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -173,8 +171,7 @@ public static class EnumExtension
|
||||
/// <returns></returns>
|
||||
public static string GetTheme(this object value)
|
||||
{
|
||||
return value.GetType().GetMember(value.ToString() ?? string.Empty).FirstOrDefault()
|
||||
?.GetCustomAttribute<ThemeAttribute>()?.Theme;
|
||||
return value.GetType().GetField(value.ToString()!)?.GetCustomAttribute<ThemeAttribute>()?.Theme;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -186,10 +183,10 @@ public static class EnumExtension
|
||||
{
|
||||
if (!type.IsEnum)
|
||||
throw new ArgumentException("Type '" + type.Name + "' is not an enum.");
|
||||
var arr = System.Enum.GetNames(type);
|
||||
var arr = Enum.GetNames(type);
|
||||
return arr.Select(sl =>
|
||||
{
|
||||
var item = System.Enum.Parse(type, sl);
|
||||
var item = Enum.Parse(type, sl);
|
||||
return new EnumEntity
|
||||
{
|
||||
Name = item.ToString(),
|
||||
@ -210,8 +207,8 @@ public static class EnumExtension
|
||||
{
|
||||
if (!type.IsEnum)
|
||||
throw new ArgumentException("Type '" + type.Name + "' is not an enum.");
|
||||
var arr = System.Enum.GetNames(type);
|
||||
return arr.Select(name => (T)System.Enum.Parse(type, name)).ToList();
|
||||
var arr = Enum.GetNames(type);
|
||||
return arr.Select(name => (T)Enum.Parse(type, name)).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
@ -223,20 +220,20 @@ public class EnumEntity
|
||||
/// <summary>
|
||||
/// 枚举的描述
|
||||
/// </summary>
|
||||
public string Describe { set; get; }
|
||||
public string Describe { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 枚举的样式
|
||||
/// </summary>
|
||||
public string Theme { set; get; }
|
||||
public string Theme { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 枚举名称
|
||||
/// </summary>
|
||||
public string Name { set; get; }
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 枚举对象的值
|
||||
/// </summary>
|
||||
public int Value { set; get; }
|
||||
public int Value { get; set; }
|
||||
}
|
||||
@ -2,7 +2,7 @@
|
||||
"name": "admin.net.pro",
|
||||
"type": "module",
|
||||
"version": "2.4.33",
|
||||
"lastBuildTime": "2024.09.30",
|
||||
"lastBuildTime": "2024.10.04",
|
||||
"description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架",
|
||||
"author": "zuohuaijun",
|
||||
"license": "MIT",
|
||||
@ -47,7 +47,7 @@
|
||||
"mqtt": "^5.10.1",
|
||||
"nprogress": "^0.2.0",
|
||||
"ol": "^10.2.1",
|
||||
"pinia": "^2.2.2",
|
||||
"pinia": "^2.2.4",
|
||||
"print-js": "^1.6.0",
|
||||
"push.js": "^1.0.12",
|
||||
"qrcodejs2-fixes": "^0.0.2",
|
||||
@ -59,7 +59,7 @@
|
||||
"splitpanes": "^3.1.5",
|
||||
"vcrontab-3": "^3.3.22",
|
||||
"vform3-builds": "^3.0.10",
|
||||
"vue": "^3.5.10",
|
||||
"vue": "^3.5.11",
|
||||
"vue-clipboard3": "^2.0.0",
|
||||
"vue-demi": "0.14.6",
|
||||
"vue-draggable-plus": "^0.5.3",
|
||||
@ -70,7 +70,7 @@
|
||||
"vue-router": "^4.4.5",
|
||||
"vue-signature-pad": "^3.0.2",
|
||||
"vue3-tree-org": "^4.2.2",
|
||||
"vxe-pc-ui": "^4.2.11",
|
||||
"vxe-pc-ui": "^4.2.12",
|
||||
"vxe-table": "^4.7.59",
|
||||
"vxe-table-plugin-element": "^4.0.4",
|
||||
"vxe-table-plugin-export-xlsx": "^4.0.6",
|
||||
@ -84,15 +84,15 @@
|
||||
"@types/node": "^20.16.5",
|
||||
"@types/nprogress": "^0.2.3",
|
||||
"@types/sortablejs": "^1.15.8",
|
||||
"@typescript-eslint/eslint-plugin": "^8.7.0",
|
||||
"@typescript-eslint/parser": "^8.7.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.8.0",
|
||||
"@typescript-eslint/parser": "^8.8.0",
|
||||
"@vitejs/plugin-vue": "^5.1.4",
|
||||
"@vitejs/plugin-vue-jsx": "^4.0.1",
|
||||
"@vue/compiler-sfc": "^3.5.10",
|
||||
"@vue/compiler-sfc": "^3.5.11",
|
||||
"code-inspector-plugin": "^0.16.1",
|
||||
"eslint": "^9.11.1",
|
||||
"eslint-plugin-vue": "^9.28.0",
|
||||
"globals": "^15.8.0",
|
||||
"globals": "^15.10.0",
|
||||
"less": "^4.2.0",
|
||||
"prettier": "^3.3.3",
|
||||
"rollup-plugin-visualizer": "^5.12.0",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user