public static IOrderedEnumerable <string> PossiblePropertyNames(this PropertyInfo propertyInfo, IEnumerable <string> schemaNames = null) { var possibleNames = new Func <PropertyInfo, string[]>[] { p => new[] { Inflector.MakeInitialUpperCase(p.DeclaringType?.Name) + Inflector.MakeInitialUpperCase(p.Name) }, p => PrefixWithSchemaName(p.Name) .ToArray(), p => new[] { Inflector.MakeInitialUpperCase(p.Name) }, p => new[] { Inflector.CollapseNames(p.DeclaringType?.Name, p.Name) }, p => Inflector.StripLeftTerms(p.Name) .ToArray() }; // Important: The IOrderedEnumerable and OrderBy clause here preserves the naming precedence in possible names return(possibleNames.SelectMany(f => f(propertyInfo)).OrderBy(x => true)); IEnumerable <string> PrefixWithSchemaName(string name) { if (schemaNames == null) { yield break; } foreach (var schemaName in schemaNames) { yield return(Inflector.MakeInitialUpperCase(schemaName) + name); } } }
public void CollapseNames_test_ambiguous_overlap() { var result = Inflector.CollapseNames( "AlphaBravoCharlieBravoCharlie", "BravoCharlieCharlie", "CharlieDelta"); Assert.AreEqual("AlphaBravoCharlieBravoCharlieCharlieDelta", result); }
public void CollapseNames_test_lower_case_first_character() { var result = Inflector.CollapseNames("alpha", "Alpha", "alpha"); Assert.AreEqual("Alpha", result); }
public void CollapseNames_test_three_terms() { var result = Inflector.CollapseNames("AlphaBravo", "BravoCharlie", "CharlieDelta"); Assert.AreEqual("AlphaBravoCharlieDelta", result); }
public void CollapseNames_test_subsumed() { var result = Inflector.CollapseNames("AlphaBravo", "AlphaBravoCharlieDelta"); Assert.AreEqual("AlphaBravoCharlieDelta", result); }
public void CollapseNames_test_one_overlap() { var result = Inflector.CollapseNames("AlphaBravo", "BravoCharlie"); Assert.AreEqual("AlphaBravoCharlie", result); }