/// <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); }
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(); }
/// <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); }
/// <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()); }
/// <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)); }
/// <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; }
/// <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; }
/// <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); }
public virtual string Format(ILanguageWords words, string oldName, Case newCase, Singularization singularization) { var parts = words.GetWords(oldName); return Format(words, parts, newCase, singularization); }