mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 20:06:33 +00:00
Added shape properties
This commit is contained in:
1 parent
c0957a3075
commit
07d9a5f784
31 files changed
+373
-114
No files matched your search
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Humanizer;
|
||||
|
||||
namespace Artemis.UI.Shared.Utilities
|
||||
{
|
||||
public static class EnumUtilities
|
||||
{
|
||||
public static string Description(this Enum value)
|
||||
{
|
||||
var attributes = value.GetType().GetField(value.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false);
|
||||
if (attributes.Any())
|
||||
return (attributes.First() as DescriptionAttribute).Description;
|
||||
|
||||
// If no description is found, the least we can do is replace underscores with spaces
|
||||
// You can add your own custom default formatting logic here
|
||||
var ti = CultureInfo.CurrentCulture.TextInfo;
|
||||
return ti.ToTitleCase(ti.ToLower(value.ToString().Replace("_", " ")));
|
||||
}
|
||||
|
||||
public static IEnumerable<ValueDescription> GetAllValuesAndDescriptions(Type t)
|
||||
{
|
||||
if (!t.IsEnum)
|
||||
throw new ArgumentException($"{nameof(t)} must be an enum type");
|
||||
|
||||
return Enum.GetValues(t).Cast<Enum>().Select(e => new ValueDescription {Value = e, Description = e.Humanize()}).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public class ValueDescription
|
||||
{
|
||||
public object Value { get; set; }
|
||||
public string Description { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user