/// <summary> /// Enum의 문자열 값으로 Enum의 Description을 리턴함. /// </summary> /// <param name="TypeOfEnum">Enum의 Type(typeof(SeatType)과 같이 사용할 수 있음)</param> /// <param name="EnumName"></param> /// <returns></returns> /// <example> /// <code> /// public enum SeatType /// { /// [Description("Window")] Window = 1, /// [Description("Aisle")] Aisle = 2, /// [Description("Anything Except Seat Near Bathroom")] AnythingExceptSeatNearBathroom /// } /// SeatType st = SeatType.Window; /// string s = CReflection.GetEnumDescriptionByName(st, "AnythingExceptSeatNearBathroom"); //"Anything Except Seat Near Bathroom" /// </code> /// </example> public static string GetDescriptionByName <T>(string EnumName, string DefaultValue) { foreach (FieldInfo fi in CEnum.GetFields <T>()) { if (fi.Name == EnumName) { DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); if (attributes.Length > 0) { return(attributes[0].Description); } } } return(DefaultValue); }
/// <summary> /// Enum 형식의 Value, Name, Description를 각각 "Value", "Name", "Description" 필드를 가진 /// DataTable을 리턴함. /// </summary> /// <param name="TypeOfEnum">Enum의 Type(typeof(SeatType)과 같이 사용할 수 있음)</param> /// <returns>"Value", "Name", "Description" 필드를 가진 DataTable</returns> /// <example> /// 다음은 SeatType 형식을 DataTable로 바꾸어 모든 필드와 값을 출력합니다. /// <code> /// <![CDATA[ /// public enum SeatType /// { /// [Description("Window")] Window = 1, /// [Description("Aisle")] Aisle = 2, /// [Description("Anything Except Seat Near Bathroom")] AnythingExceptSeatNearBathroom /// } /// DataTable dt = CEnum.GetDataTableByValueNameDescription<SeatType>(); /// string s = CDataTable.ToString(dt, "\r\n", ",", "(null)"); /// Console.WriteLine(s); /// --결과 /// 1,Window,Window /// 2,Aisle,Aisle /// 3,AnythingExceptSeatNearBathroom,Anything Except Seat Near Bathroom /// ]]> /// </code> /// </example> public static DataTable GetDataTableByValueNameDescription <T>() { List <int> aValue = new List <int>(); List <string> aName = new List <string>(); List <string> aDescription = new List <string>(); DataTable dt = new DataTable(); dt.Columns.Add("Value", typeof(int)); dt.Columns.Add("Name", typeof(string)); dt.Columns.Add("Description", typeof(string)); foreach (FieldInfo fi in GetFields <T>()) { DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); string Name = fi.Name; string Desc = (attributes.Length > 0) ? attributes[0].Description : Name; //값에 -1, 0, 1이 있다면 -1, 0, 1 순이 아닌 0, 1, -1 순으로 정렬되므로 //이곳에서 값을 추가함. foreach (T EnumValue in CEnum.GetAllValues <T>()) { if (EnumValue.ToString() == Name) { aValue.Add(Convert.ToInt32(EnumValue)); break; } } aName.Add(Name); aDescription.Add(Desc); } for (int i = 0, i2 = aValue.Count; i < i2; i++) { dt.Rows.Add(aValue[i], aName[i], aDescription[i]); } return(dt); }
public static void ConvertWaveToMp3(string FullPathWave, string FullPathMp3, string LameFullPath, WaveToMp3Preset Preset) { if (string.IsNullOrEmpty(LameFullPath)) { LameFullPath = "lame.exe"; } //lame.exe --preset cbr 256 test.wav test.mp3 //lame.exe --preset fast standard test.wav test.mp3 string sPreset = CEnum.GetDescriptionByValue <WaveToMp3Preset>(Preset); Process p = new Process(); string Arguments = string.Format(@"--preset {0} ""{1}"" ""{2}""", sPreset, FullPathWave, FullPathMp3); ProcessStartInfo ps = new ProcessStartInfo(LameFullPath, Arguments); ps.WindowStyle = ProcessWindowStyle.Hidden; p.StartInfo = ps; p.Start(); p.WaitForExit(10000); }