Implementation of the basic functionallity

This commit is contained in:
2024-02-06 19:47:06 +01:00
parent a6c7828fbe
commit f31f6f94ff
42 changed files with 6875 additions and 11 deletions

View File

@@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace System
{
// ================================================================================================================================== //
// Source: https://git.am-wd.de/am.wd/common/-/blob/d4b390ad911ce302cc371bb2121fa9c31db1674a/AMWD.Common/Extensions/EnumExtensions.cs //
// ================================================================================================================================== //
[Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static class EnumExtensions
{
private static IEnumerable<TAttribute> GetAttributes<TAttribute>(this Enum value)
where TAttribute : Attribute
{
var fieldInfo = value.GetType().GetField(value.ToString());
if (fieldInfo == null)
return Array.Empty<TAttribute>();
return fieldInfo.GetCustomAttributes(typeof(TAttribute), inherit: false).Cast<TAttribute>();
}
private static TAttribute GetAttribute<TAttribute>(this Enum value)
where TAttribute : Attribute
=> value.GetAttributes<TAttribute>().FirstOrDefault();
public static string GetDescription(this Enum value)
=> value.GetAttribute<DescriptionAttribute>()?.Description ?? value.ToString();
}
}