Files
UmaViewer/Assets/Scripts/Audio/NAudio/Utils/FieldDescriptionHelper.cs
T
2022-09-10 16:59:44 +08:00

42 lines
1.2 KiB
C#

using System;
using System.Reflection;
namespace NAudio.Utils
{
/// <summary>
/// Helper to get descriptions
/// </summary>
public static class FieldDescriptionHelper
{
/// <summary>
/// Describes the Guid by looking for a FieldDescription attribute on the specified class
/// </summary>
public static string Describe(Type t, Guid guid)
{
// when we go to .NET 3.5, use LINQ for this
foreach (var f in t
#if NETFX_CORE
.GetRuntimeFields())
#else
.GetFields(BindingFlags.Static | BindingFlags.Public))
#endif
{
if (f.IsPublic && f.IsStatic && f.FieldType == typeof (Guid) && (Guid) f.GetValue(null) == guid)
{
foreach (var a in f.GetCustomAttributes(false))
{
var d = a as FieldDescriptionAttribute;
if (d != null)
{
return d.Description;
}
}
// no attribute, return the name
return f.Name;
}
}
return guid.ToString();
}
}
}