mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2026-11-11 04:57:15 +00:00
Fixed warnings
This commit is contained in:
1 parent
57dc9afb32
commit
a0a1521658
118 files changed
+802
-1181
No files matched your search
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.Wooting.Helper
|
||||
{
|
||||
@@ -14,26 +13,21 @@ namespace RGB.NET.Devices.Wooting.Helper
|
||||
/// Gets the value of the <see cref="DescriptionAttribute"/>.
|
||||
/// </summary>
|
||||
/// <param name="source">The enum value to get the description from.</param>
|
||||
/// <typeparam name="T">The generic enum-type</typeparam>
|
||||
/// <returns>The value of the <see cref="DescriptionAttribute"/> or the <see cref="Enum.ToString()" /> result of the source.</returns>
|
||||
internal static string GetDescription<T>(this T source)
|
||||
where T : struct
|
||||
{
|
||||
return source.GetAttribute<DescriptionAttribute, T>()?.Description ?? source.ToString();
|
||||
}
|
||||
|
||||
/// <returns>The value of the <see cref="DescriptionAttribute"/> or the <see cref="System.Enum.ToString()" /> result of the source.</returns>
|
||||
internal static string? GetDescription(this System.Enum source)
|
||||
=> source.GetAttribute<DescriptionAttribute>()?.Description ?? source.ToString();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the attribute of type T.
|
||||
/// </summary>
|
||||
/// <param name="source">The enum value to get the attribute from</param>
|
||||
/// <typeparam name="T">The generic attribute type</typeparam>
|
||||
/// <typeparam name="TEnum">The generic enum-type</typeparam>
|
||||
/// <returns>The <see cref="Attribute"/>.</returns>
|
||||
private static T GetAttribute<T, TEnum>(this TEnum source)
|
||||
private static T? GetAttribute<T>(this System.Enum source)
|
||||
where T : Attribute
|
||||
where TEnum : struct
|
||||
{
|
||||
FieldInfo fi = source.GetType().GetField(source.ToString());
|
||||
FieldInfo? fi = source.GetType().GetField(source.ToString());
|
||||
if (fi == null) return null;
|
||||
T[] attributes = (T[])fi.GetCustomAttributes(typeof(T), false);
|
||||
return attributes.Length > 0 ? attributes[0] : null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user