Beispiel #1
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) });
            }
        }
Beispiel #2
0
        private static string[] GetIndividualEnumTerms(Enum value, TermAttribute termAttribute, ITermSettings termSettings, CultureInfo culture)
        {
            string[] values = termAttribute?.Values?.Any() ?? false
                ? termAttribute.Values
                : new[]
            {
                TermCaseResolver.ApplyCase(
                    value.ToString(),
                    termAttribute.GetCaseOrNull() ?? termSettings.GetCaseOrNull() ?? DefaultCase)
            };

            string termFormat = termAttribute.GetFormatOrNull() ?? termSettings.GetFormatOrNull();

            return(termFormat != null
                ? values.Select(x => FormatValue(x, termFormat, culture)).ToArray()
                : values);
        }
Beispiel #3
0
 private static string ApplyCaseWithoutWordBreak(string value, TermCase termCase)
 {
     string[] words = value.Split(' ');
     return(TermCaseResolver.ApplyCase(words, termCase));
 }
Beispiel #4
0
 public static string ApplyTo(this TermCase termCase, string value)
 {
     return(TermCaseResolver.ApplyCase(value, termCase));
 }