Skip to content

Commit

Permalink
Merge pull request #51 from Takasaki-Studio/dotnet8-enum-description
Browse files Browse the repository at this point in the history
Add: get enum description and update dependencies
  • Loading branch information
Takasakiii authored Feb 14, 2024
2 parents 92bf821 + 77a52fa commit 1fab996
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 8 deletions.
1 change: 0 additions & 1 deletion .tool-versions

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>2.0.4</Version>
<Version>2.0.5</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>TakasakiStudio.Lina.AspNet</PackageId>
<Authors>TakasakiStudio</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>2.0.4</Version>
<Version>2.0.5</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>TakasakiStudio.Lina.AutoDependencyInjection</PackageId>
<Authors>TakasakiStudio</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>2.0.4</Version>
<Version>2.0.5</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>TakasakiStudio.Lina.Common</PackageId>
<Title>TakasakiStudio.Lina.Common</Title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>2.0.4</Version>
<Version>2.0.5</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>TakasakiStudio.Lina.Database</PackageId>
<Title>TakasakiStudio.Lina.Database</Title>
Expand All @@ -20,7 +20,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
22 changes: 22 additions & 0 deletions TakasakiStudio.Lina.Utils/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ namespace TakasakiStudio.Lina.Utils.Extensions;

public static class EnumExtensions
{
/// <summary>
/// Get enum description or string name
/// </summary>
/// <param name="value">Enum value</param>
/// <typeparam name="T">Enum type</typeparam>
/// <returns>Description</returns>
public static string? GetDescription<T>(this T value) where T : struct
{
var type = typeof(T);

var name = Enum.GetName(type, value);

if (string.IsNullOrWhiteSpace(name))
return value.ToString();

var descriptionAttribute =
(DescriptionAttribute[]?)type.GetField(name)
?.GetCustomAttributes(typeof(DescriptionAttribute), false);

return descriptionAttribute?.FirstOrDefault()?.Description ?? value.ToString();
}

/// <summary>
/// Convert enum as option
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion TakasakiStudio.Lina.Utils/TakasakiStudio.Lina.Utils.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>2.0.4</Version>
<Version>2.0.5</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>TakasakiStudio.Lina.Utils</PackageId>
<Title>TakasakiStudio.Lina.Utils</Title>
Expand Down
2 changes: 1 addition & 1 deletion TakasakiStudio.Lina/TakasakiStudio.Lina.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>2.0.4</Version>
<Version>2.0.5</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>TakasakiStudio.Lina</PackageId>
<Title>TakasakiStudio.Lina</Title>
Expand Down

0 comments on commit 1fab996

Please sign in to comment.