diff --git a/push2nuget.ps1 b/push2nuget.ps1 deleted file mode 100644 index 24d0798..0000000 --- a/push2nuget.ps1 +++ /dev/null @@ -1,25 +0,0 @@ -Param( -# Nuget APIKey - [string] $apikey -) - -if ($apikey -eq $null -or $apikey -eq "") -{ - Write-Error "require apiKey"; - return; -} - -rm -r ./build/nupkgs -dotnet build -c Release -$files = Get-ChildItem -Path ./build/nupkgs/ -Filter *.nupkg -foreach ($file in $files) -{ - dotnet nuget push $file.fullName --skip-duplicate --api-key $apikey --source https://api.nuget.org/v3/index.json - nuget add $file.fullName -source d:\nuget-pkg -} -$files = Get-ChildItem -Path ./build/nupkgs/ -Filter *.snupkg -foreach ($file in $files) -{ - dotnet nuget push $file.fullName --skip-duplicate --api-key $apikey --source https://api.nuget.org/v3/index.json - nuget add $file.fullName -source d:\nuget-pkg -} \ No newline at end of file diff --git a/src/Attributes/LocalizationAttribute.cs b/src/Attributes/LocalizationAttribute.cs new file mode 100644 index 0000000..5658339 --- /dev/null +++ b/src/Attributes/LocalizationAttribute.cs @@ -0,0 +1,24 @@ +namespace NSExt.Attributes; + +/// +/// 指定本地化资源类型 +/// +[AttributeUsage(AttributeTargets.Property | AttributeTargets.Class | AttributeTargets.Field)] +public class LocalizationAttribute : Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public LocalizationAttribute(Type resourceClass) + { + ResourceClass = resourceClass; + } + + /// + /// Gets or sets 资源类型 + /// + /// + /// 资源类型 + /// + public Type ResourceClass { get; set; } +} \ No newline at end of file diff --git a/src/Extensions/EnumExtensions.cs b/src/Extensions/EnumExtensions.cs index 80ae7bd..0c75c95 100644 --- a/src/Extensions/EnumExtensions.cs +++ b/src/Extensions/EnumExtensions.cs @@ -1,3 +1,6 @@ +using System.Reflection; +using NSExt.Attributes; + namespace NSExt.Extensions; /// @@ -12,9 +15,15 @@ public static class EnumExtensions /// description属性 public static string Desc(this Enum e) { - var t = e.GetType(); - var fi = t.GetField(Enum.GetName(t, e)!); - var attrs = (DescriptionAttribute[])fi!.GetCustomAttributes(typeof(DescriptionAttribute), false); - return (attrs.Length != 0 ? attrs[0].Description : Enum.GetName(t, e)) ?? string.Empty; + var t = e.GetType(); + var fi = t.GetField(Enum.GetName(t, e)!); + var descAttr = fi!.GetCustomAttribute(false); + if (descAttr is null) { + return Enum.GetName(t, e); + } + + var str = descAttr.Description; + var locAttr = fi!.GetCustomAttribute(false); + return locAttr is null ? str : locAttr.ResourceClass.GetProperty(str)?.GetValue(default) as string ?? str; } } \ No newline at end of file