Пример #1
0
        /// <summary>
        ///     Returns the length of the longest ConsoleType item.
        ///     DisplayName or EnumName
        /// </summary>
        /// <returns></returns>
        public static int GetLengthOfLongestConsoleType()
        {
            // Longest type alread getted -> return;
            if (LongestTypeLength != 0)
            {
                return(LongestTypeLength);
            }

            // Search for longest console type
            foreach (ConsoleType consoleType in Enum.GetValues(typeof(ConsoleType)))
            {
                ConsoleTypeProperties consoleTypeProperties = GetConsoleTypeProperties(consoleType);
                if (consoleTypeProperties.TypeName != null)
                {
                    string displayName = ColorUtils.CleanUp(consoleTypeProperties.TypeName);
                    if (displayName.Length > LongestTypeLength)
                    {
                        LongestTypeLength = displayName.Length;
                    }
                }
                else if ($"{consoleType}".Length > LongestTypeLength)
                {
                    LongestTypeLength = $"{consoleType}".Length;
                }
            }

            return(LongestTypeLength);
        }
Пример #2
0
        /// <summary>
        ///     Returns the propertys for the given ConsoleType
        /// </summary>
        /// <param name="consoleType">The requested console type</param>
        /// <returns></returns>
        public static ConsoleTypeProperties GetConsoleTypeProperties(ConsoleType consoleType)
        {
            MemberInfo[]          memberInfo = consoleType.GetType().GetMember(consoleType.ToString());
            ConsoleTypeProperties attributes =
                (ConsoleTypeProperties)memberInfo[0].GetCustomAttribute(typeof(ConsoleTypeProperties), false);

            return(attributes);
        }