Hue/Hue/lib/Helper.cs
2018-04-20 19:50:28 +00:00

38 lines
1.1 KiB
C#

using System;
using System.ComponentModel;
using System.Reflection;
namespace BlubbFish.IoT.Hue.lib {
class Helper {
internal static void WriteError(String text) {
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine("ERROR: " + text);
Console.ResetColor();
}
public static String GetEnumDescription(Enum value) {
FieldInfo fi = value.GetType().GetField(value.ToString());
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attributes != null && attributes.Length > 0) {
return attributes[0].Description;
} else {
return value.ToString();
}
}
}
public static class StringHelper {
public static String ToEnumString(this String text) {
if(text.Length == 0) {
return text;
}
if(text.Length == 1) {
return text.ToUpper();
}
text = text.Replace(" ", "");
text = text.ToLower();
return text[0].ToString().ToUpper() + text.Substring(1);
}
}
}