コード例 #1
0
        public string GetCommonPrefix()
        {
            if (EnumConstants.Count < 2)
            {
                return("");
            }

            string prefix = "";
            int    i      = 0;

            while (true)
            {
                char c = EnumConstants[0][i];
                if (!EnumConstants.All(e => e[i] == c))
                {
                    break;
                }
                if (EnumConstants.Any(e => e.Length == i))
                {
                    // Prefix is already one of the enumerators,
                    // can't use this prefix
                    return("");
                }
                i++;
                prefix += c;
            }
            return(prefix);
        }
コード例 #2
0
        public string GetCommonSuffix()
        {
            if (EnumConstants.Count < 2)
            {
                return("");
            }

            string suffix = "";
            int    i      = 1;

            while (true)
            {
                string enumConstant = EnumConstants[0];
                char   c            = enumConstant[enumConstant.Length - i];
                if (!EnumConstants.All(e => e[e.Length - i] == c))
                {
                    break;
                }
                i++;
                suffix = c + suffix;
            }
            return(suffix);
        }