Ejemplo n.º 1
0
        private static void AddToCache <T>(UnitType unitType)
            where T : struct, IComparable, IFormattable, IConvertible
        {
            Type enumType = typeof(T);

            int[] a = (int[])Enum.GetValues(enumType);

            for (int x = 0; x < a.Length; x++)
            {
                MemberInfo parentInfo = GetMemberInfo(enumType, Enum.GetName(enumType, x));
                string     parrentKey = AttributeReader.GetAbbreviation(parentInfo);

                for (int i = 0; i < a.Length; i++)
                {
                    if (x == i)
                    {
                        continue;
                    }

                    MemberInfo info = GetMemberInfo(enumType, Enum.GetName(enumType, i));

                    string key = string.Format(
                        CultureInfo.InvariantCulture,
                        ExpressionFormat,
                        parrentKey,
                        AttributeReader.GetAbbreviation(info));

                    convertionCache.Add(
                        key, new ConvertionMap(unitType, x, i));
                }
            }
        }
Ejemplo n.º 2
0
        public void GetAbbreviation()
        {
            string result = AttributeReader.GetAbbreviation <SpeedUnit>(SpeedUnit.MilePerHour);

            Assert.AreEqual("mph", result);

            result = AttributeReader.GetAbbreviation <SpeedUnit>(SpeedUnit.Knot);
            Assert.AreEqual("knot", result);
        }
Ejemplo n.º 3
0
        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);
                }
            }
        }