Exemple #1
0
        public static string ToPlural(string targetValue)
        {
            if (_service == null)
            {
                _service = PluralizationService.CreateService(System.Globalization.CultureInfo.GetCultureInfo(CultureInfo));
            }

            var word = GetLastWord(targetValue);

            string newWord;

            if (!Dictionary1.TryGetValue(word.ToLower(), out newWord))
            {
                newWord = _service.IsPlural(word)
                                        ? word
                                        : _service.Pluralize(word);
            }

            if (string.Compare(word, newWord, true) != 0)
            {
                if (char.IsUpper(word[0]))
                {
                    newWord = char.ToUpper(newWord[0]) + newWord.Substring(1, newWord.Length - 1);
                }

                if (word == targetValue)
                {
                    return(newWord);
                }

                return(targetValue.Substring(0, targetValue.Length - word.Length) + newWord);
            }

            return(targetValue);
        }
Exemple #2
0
        public static string ToSingular(string targetValue)
        {
            if (_service == null)
            {
                _service = PluralizationService.CreateService(System.Globalization.CultureInfo.GetCultureInfo(CultureInfo));
            }

            var word = GetLastWord(targetValue);

            var newWord =
                Dictionary1
                .Where(dic => string.Compare(dic.Value, word, ignoreCase: true) == 0)
                .Select(dic => dic.Key)
                .FirstOrDefault()
                ??
                (_service.IsSingular(word)
                                        ? word
                                        : _service.Singularize(word));

            if (string.Compare(word, newWord, ignoreCase: true) != 0)
            {
                if (char.IsUpper(word[0]))
                {
                    newWord = char.ToUpper(newWord[0]) + newWord.Substring(1, newWord.Length - 1);
                }

                if (word == targetValue)
                {
                    return(newWord);
                }

                return(targetValue.Substring(0, targetValue.Length - word.Length) + newWord);
            }

            return(targetValue);
        }
Exemple #3
0
        public static void Main()
        {
            Dictionary1 <Guid, String> _D = new Dictionary1 <Guid, string>();

            _D.Add(Guid.NewGuid(), "foo");
        }