コード例 #1
0
ファイル: NameFormatter.cs プロジェクト: yiki2/dblinq2007
 /// <summary>
 /// Gets the singularization.
 /// </summary>
 /// <param name="singularization">The singularization.</param>
 /// <param name="nameFormat">The name format.</param>
 /// <returns></returns>
 protected virtual Singularization GetSingularization(Singularization singularization, NameFormat nameFormat)
 {
     if (!nameFormat.Pluralize)
     {
         return(Singularization.DontChange);
     }
     return(singularization);
 }
コード例 #2
0
 private string Format(ILanguageWords words, IList<string> parts, Case newCase, Singularization singularization)
 {
     var result = new StringBuilder();
     for (int partIndex = 0; partIndex < parts.Count; partIndex++)
     {
         Position position = 0;
         if (partIndex == 0)
             position |= Position.First;
         if (partIndex == parts.Count - 1)
             position |= Position.Last;
         result.Append(AdjustPart(words, parts[partIndex], position, newCase, singularization));
     }
     return result.ToString();
 }
コード例 #3
0
ファイル: NameFormatter.cs プロジェクト: yiki2/dblinq2007
        /// <summary>
        /// Adjusts the part.
        /// </summary>
        /// <param name="words">The words.</param>
        /// <param name="part">The part.</param>
        /// <param name="position">The position.</param>
        /// <param name="newCase">The new case.</param>
        /// <param name="singularization">The singularization.</param>
        /// <returns></returns>
        protected virtual string AdjustPart(ILanguageWords words, string part, Position position, Case newCase, Singularization singularization)
        {
            if (singularization != Singularization.DontChange && (position & Position.Last) != 0)
            {
                if (singularization == Singularization.Singular)
                {
                    part = words.Singularize(part);
                }
                else
                {
                    part = words.Pluralize(part);
                }
            }
            Case applyCase = newCase;

            if (applyCase == Case.camelCase && (position & Position.First) == 0)
            {
                applyCase = Case.PascalCase;
            }
            switch (applyCase)
            {
            case Case.Leave:
                break;

            case Case.camelCase:
                part = ToCamelCase(part);
                break;

            case Case.PascalCase:
                part = ToPascalCase(part);
                break;

            case Case.NetCase:
                part = ToNetCase(part);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(part);
        }
コード例 #4
0
ファイル: NameFormatter.cs プロジェクト: yiki2/dblinq2007
        /// <summary>
        /// Formats the specified words.
        /// </summary>
        /// <param name="words">The words.</param>
        /// <param name="parts">The parts.</param>
        /// <param name="newCase">The new case.</param>
        /// <param name="singularization">The singularization.</param>
        /// <returns></returns>
        private string Format(ILanguageWords words, IList <string> parts, Case newCase, Singularization singularization)
        {
            var result = new StringBuilder();

            for (int partIndex = 0; partIndex < parts.Count; partIndex++)
            {
                Position position = 0;
                if (partIndex == 0)
                {
                    position |= Position.First;
                }
                if (partIndex == parts.Count - 1)
                {
                    position |= Position.Last;
                }
                result.Append(AdjustPart(words, parts[partIndex], position, newCase, singularization));
            }
            return(result.ToString());
        }
コード例 #5
0
ファイル: NameFormatter.cs プロジェクト: yiki2/dblinq2007
        /// <summary>
        /// Formats the specified words.
        /// </summary>
        /// <param name="words">The words.</param>
        /// <param name="oldName">The old name.</param>
        /// <param name="newCase">The new case.</param>
        /// <param name="singularization">The singularization.</param>
        /// <returns></returns>
        public virtual string Format(ILanguageWords words, string oldName, Case newCase, Singularization singularization)
        {
            var parts = ExtractWordsFromCaseAndLanguage(words, oldName);

            return(Format(words, parts, newCase, singularization));
        }
コード例 #6
0
 /// <summary>
 /// Gets the singularization.
 /// </summary>
 /// <param name="singularization">The singularization.</param>
 /// <param name="nameFormat">The name format.</param>
 /// <returns></returns>
 protected virtual Singularization GetSingularization(Singularization singularization, NameFormat nameFormat)
 {
     if (!nameFormat.Pluralize)
         return Singularization.DontChange;
     return singularization;
 }
コード例 #7
0
 /// <summary>
 /// Adjusts the part.
 /// </summary>
 /// <param name="words">The words.</param>
 /// <param name="part">The part.</param>
 /// <param name="position">The position.</param>
 /// <param name="newCase">The new case.</param>
 /// <param name="singularization">The singularization.</param>
 /// <returns></returns>
 protected virtual string AdjustPart(ILanguageWords words, string part, Position position, Case newCase, Singularization singularization)
 {
     if (singularization != Singularization.DontChange && (position & Position.Last) != 0)
     {
         if (singularization == Singularization.Singular)
             part = words.Singularize(part);
         else
             part = words.Pluralize(part);
     }
     Case applyCase = newCase;
     if (applyCase == Case.camelCase && (position & Position.First) == 0)
         applyCase = Case.PascalCase;
     switch (applyCase)
     {
     case Case.Leave:
         break;
     case Case.camelCase:
         part = ToCamelCase(part);
         break;
     case Case.PascalCase:
         part = ToPascalCase(part);
         break;
     case Case.NetCase:
         part = ToNetCase(part);
         break;
     default:
         throw new ArgumentOutOfRangeException();
     }
     return part;
 }
コード例 #8
0
 /// <summary>
 /// Formats the specified words.
 /// </summary>
 /// <param name="words">The words.</param>
 /// <param name="oldName">The old name.</param>
 /// <param name="newCase">The new case.</param>
 /// <param name="singularization">The singularization.</param>
 /// <returns></returns>
 public virtual string Format(ILanguageWords words, string oldName, Case newCase, Singularization singularization)
 {
     var parts = ExtractWordsFromCaseAndLanguage(words, oldName);
     return Format(words, parts, newCase, singularization);
 }
コード例 #9
0
 public virtual string Format(ILanguageWords words, string oldName, Case newCase, Singularization singularization)
 {
     var parts = words.GetWords(oldName);
     return Format(words, parts, newCase, singularization);
 }