Moving structure as preparation for docs

This commit is contained in:
2025-08-06 21:05:47 +02:00
parent 885079ae70
commit 799a014b15
117 changed files with 629 additions and 664 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();
}
}