Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: get enum description and update dependencies #51

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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