public string GetName(RenameableObject renamable, string text) { var opt = Options.Defaults; if (renamable.Renamed) return text.Prefix().Dot(renamable.Name); bool skipRules = false; string prefix = text.Prefix(); var name = BeforeRenaming(renamable, out skipRules); if (!skipRules) { name = Rename(renamable, text); } name = AfterRenaming(renamable, name); renamable.Name = name; return prefix.Dot(name); }
public string Rename(RenameableObject obj, string text) { var options = Options.ForContext(obj.GetNameContext()); var name = obj.Name; if (options.ApplyRegex == ApplyRegexEnum.InsteadOfRules) return ApplyRegex(name, options.RegexMatch, options.RegexReplace); if (options.ApplyRegex == ApplyRegexEnum.BeforeRules) name = ApplyRegex(name, options.RegexMatch, options.RegexReplace); if (!String.IsNullOrEmpty(options.RemovePrefixes)) { foreach (var prefix in options.ListRemovePrefixes()) { if (name.ToLower().StartsWith(prefix.ToLower())) { name = name.Remove(0, prefix.Length); } } } if (!String.IsNullOrEmpty(options.RemoveSuffixes)) { foreach (var suffix in options.ListRemoveSuffixes()) { if (name.ToLower().EndsWith(suffix.ToLower())) { name = name.Remove(name.Length - suffix.Length); } } } if (!String.IsNullOrEmpty(options.AddPrefix)) name = options.AddPrefix + name; if (!String.IsNullOrEmpty(options.AddSuffix)) name = options.AddSuffix + name; switch (options.Flexing) { case FlexingStrategyEnum.Pluralize: name = name + "s"; break; } switch (options.CaseStyle) { case CaseStyleEnum.CamelCase: name = Inflector.Camelize(name); break; case CaseStyleEnum.Undescores: name = Inflector.Underscore(name); break; case CaseStyleEnum.LowerCamelCase: name = Inflector.Pascalize(name); break; } var prop = obj as MetaScalarProperty; if (prop != null && prop.isKey && options.RemoveEntityNameFromKey) { if (name.ToLower().StartsWith(prop.EntityType.Name.ToLower())) name = name.Remove(0, prop.EntityType.Name.Length).TrimStart('_'); } if (options.ApplyRegex == ApplyRegexEnum.AfterRules) name = ApplyRegex(name, options.RegexMatch, options.RegexReplace); return name; }
public string BeforeRenaming(RenameableObject renamable, out bool skipRules) { skipRules = false; return renamable.Name; }
public string AfterRenaming(RenameableObject renamable, string newName) { return newName; }