public void GetDescription() { string result = AttributeReader.GetDescription <SpeedUnit>(SpeedUnit.MilePerHour); Assert.AreEqual("Mile/Hour", result); result = AttributeReader.GetDescription <SpeedUnit>(SpeedUnit.Knot); Assert.AreEqual("Knot", result); }
private void AddToConvertMenuItem <T>(ToolStripMenuItem p) where T : struct, IComparable, IFormattable, IConvertible { Type enumType = typeof(T); int[] a = (int[])Enum.GetValues(enumType); p.DropDownItems.Clear(); for (int x = 0; x < a.Length; x++) { MemberInfo parentInfo = GetMemberInfo(enumType, Enum.GetName(enumType, x)); string parrentKey = AttributeReader.GetAbbreviation(parentInfo); string parrentName = AttributeReader.GetDescription(parentInfo); ToolStripMenuItem t = new ToolStripMenuItem(parrentName); p.DropDownItems.Add(t); for (int i = 0; i < a.Length; i++) { if (x == i) { continue; } MemberInfo childInfo = GetMemberInfo(enumType, Enum.GetName(enumType, i)); string childName = AttributeReader.GetDescription(childInfo); string childKey = AttributeReader.GetAbbreviation(childInfo); string key = string.Format( CultureInfo.InvariantCulture, ConvertExpression.ExpressionFormat, parrentKey, childKey); ToolStripMenuItem s = new ToolStripMenuItem(childName); s.Click += new EventHandler(convert_Click); s.Tag = key; t.DropDownItems.Add(s); } } }