Add DalamudAssetManager

This commit is contained in:
Soreepeong 2023-11-21 13:49:23 +09:00 committed by goat
parent 01153a2480
commit a72f407357
17 changed files with 867 additions and 179 deletions

View file

@ -1,4 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Dalamud.Utility;
@ -8,6 +8,26 @@ namespace Dalamud.Utility;
/// </summary>
public static class EnumExtensions
{
/// <summary>
/// Gets attributes on an enum.
/// </summary>
/// <typeparam name="TAttribute">The type of attribute to get.</typeparam>
/// <param name="value">The enum value that has an attached attribute.</param>
/// <returns>The enumerable of the attached attributes.</returns>
public static IEnumerable<TAttribute> GetAttributes<TAttribute>(this Enum value)
where TAttribute : Attribute
{
var type = value.GetType();
var name = Enum.GetName(type, value);
if (name.IsNullOrEmpty())
return Array.Empty<TAttribute>();
return type.GetField(name)?
.GetCustomAttributes(false)
.OfType<TAttribute>()
?? Array.Empty<TAttribute>();
}
/// <summary>
/// Gets an attribute on an enum.
/// </summary>
@ -15,18 +35,8 @@ public static class EnumExtensions
/// <param name="value">The enum value that has an attached attribute.</param>
/// <returns>The attached attribute, if any.</returns>
public static TAttribute? GetAttribute<TAttribute>(this Enum value)
where TAttribute : Attribute
{
var type = value.GetType();
var name = Enum.GetName(type, value);
if (name.IsNullOrEmpty())
return null;
return type.GetField(name)?
.GetCustomAttributes(false)
.OfType<TAttribute>()
.SingleOrDefault();
}
where TAttribute : Attribute =>
value.GetAttributes<TAttribute>().SingleOrDefault();
/// <summary>
/// Gets an indicator if enum has been flagged as obsolete (deprecated).