示例#1
0
        private static string ResolveControlName(UIComponentMetadata metadata, FindAttribute findAttribute)
        {
            NameAttribute nameAttribute = metadata.Get <NameAttribute>(x => x.At(AttributeLevels.Declared));

            if (!string.IsNullOrWhiteSpace(nameAttribute?.Value))
            {
                return(nameAttribute.Value);
            }

            if (findAttribute is FindByLabelAttribute findByLabelAttribute && findByLabelAttribute.Match == TermMatch.Equals)
            {
                if (findByLabelAttribute.Values?.Any() ?? false)
                {
                    return(string.Join("/", findByLabelAttribute.Values));
                }
                else
                {
                    TermAttribute termAttribute = metadata.Get <TermAttribute>(x => x.At(AttributeLevels.Declared));
                    if (termAttribute?.Values?.Any() ?? false)
                    {
                        return(string.Join("/", termAttribute.Values));
                    }
                }
            }

            return(metadata.ComponentDefinitionAttribute.
                   NormalizeNameIgnoringEnding(metadata.Name).
                   ToString(TermCase.Title));
        }
示例#2
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) });
                }
            }
        }
示例#3
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) });
            }
        }
示例#4
0
        private static string ResolveControlName(UIComponentMetadata metadata, FindAttribute findAttribute)
        {
            NameAttribute nameAttribute = metadata.Get <NameAttribute>(AttributeLevels.Declared);

            if (nameAttribute != null && !string.IsNullOrWhiteSpace(nameAttribute.Value))
            {
                return(nameAttribute.Value);
            }

            FindByLabelAttribute findByLabelAttribute = findAttribute as FindByLabelAttribute;

            if (findByLabelAttribute != null)
            {
                if (findByLabelAttribute.Values != null && findByLabelAttribute.Values.Any())
                {
                    return(string.Join("/", findByLabelAttribute.Values));
                }
                else
                {
                    TermAttribute termAttribute = metadata.Get <TermAttribute>(AttributeLevels.Declared);
                    if (termAttribute != null && termAttribute.Values != null && termAttribute.Values.Any())
                    {
                        return(string.Join("/", termAttribute.Values));
                    }
                }
            }

            return(metadata.ComponentDefinitonAttribute.
                   NormalizeNameIgnoringEnding(metadata.Name).
                   ToString(TermCase.Title));
        }
示例#5
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);
        }
示例#6
0
        private static string GetControlNameFromFindAttribute(UIComponentMetadata metadata, FindAttribute findAttribute)
        {
            if (findAttribute is FindByLabelAttribute findByLabelAttribute && findByLabelAttribute.Match == TermMatch.Equals)
            {
                if (findByLabelAttribute.Values?.Any() ?? false)
                {
                    return(string.Join("/", findByLabelAttribute.Values));
                }
                else
                {
                    TermAttribute termAttribute = metadata.Get <TermAttribute>(x => x.At(AttributeLevels.Declared));
                    if (termAttribute?.Values?.Any() ?? false)
                    {
                        return(string.Join("/", termAttribute.Values));
                    }
                }
            }

            return(null);
        }