Пример #1
0
        private static string[] GetIndividualEnumTerms(Enum value, TermOptions termOptions)
        {
            TermAttribute termAttribute = GetEnumTermAttribute(value);
            bool          hasTermValue  = termAttribute != null && termAttribute.Values != null && termAttribute.Values.Any();

            string termFormat = termOptions.GetFormatOrNull()
                                ?? termAttribute.GetFormatOrNull()
                                ?? GetTermSettings(value.GetType()).GetFormatOrNull()
                                ?? null;

            if (hasTermValue)
            {
                return(termAttribute.Values.Select(x => FormatValue(x, termFormat, termOptions.Culture)).ToArray());
            }
            else
            {
                TermCase termCase = termOptions.GetCaseOrNull()
                                    ?? termAttribute.GetCaseOrNull()
                                    ?? GetTermSettings(value.GetType()).GetCaseOrNull()
                                    ?? DefaultFormat;

                if (termFormat == null || termFormat.Contains("{0}"))
                {
                    string term = termCase.ApplyTo(value.ToString());
                    return(new[] { FormatValue(term, termFormat, termOptions.Culture) });
                }
                else
                {
                    return(new[] { FormatValue(value, termFormat, termOptions.Culture) });
                }
            }
        }
Пример #2
0
        private static string[] GetIndividualEnumTerms(Enum value, TermOptions termOptions)
        {
            TermAttribute termAttribute = GetEnumTermAttribute(value);
            ITermSettings termSettings  = GetTermSettings(value.GetType());

            TermCase?termCase   = termOptions.GetCaseOrNull();
            string   termFormat = termOptions.GetFormatOrNull();

            if (termAttribute != null || termSettings != null)
            {
                string[] terms = GetIndividualEnumTerms(value, termAttribute, termSettings, termOptions.Culture);

                if (termCase.HasValue)
                {
                    terms = terms.Select(x => ApplyCaseWithoutWordBreak(x, termCase.Value)).ToArray();
                }

                return(terms.Select(x => FormatValue(x, termFormat, termOptions.Culture)).ToArray());
            }
            else if (termCase == null && (termFormat != null && !termFormat.Contains("{0}")))
            {
                return(new[] { FormatValue(value, termFormat, termOptions.Culture) });
            }
            else
            {
                string term = TermCaseResolver.ApplyCase(value.ToString(), termCase ?? DefaultCase);
                return(new[] { FormatValue(term, termFormat, termOptions.Culture) });
            }
        }