Esempio n. 1
0
        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);
                }
            }
        }
Esempio n. 2
0
        public void MakeInitialUpperCase_test()
        {
            const string source   = "theQuickBrownFoxJumpedOverTheLazyDog";
            const string expected = "TheQuickBrownFoxJumpedOverTheLazyDog";
            var          result   = Inflector.MakeInitialUpperCase(source);

            Assert.AreEqual(expected, result);
        }
        private static string GetSchemaNameParts(IEnumerable <string> schemaNameParts)
        {
            var schemaName = new StringBuilder();
            var nameParts  = schemaNameParts as string[] ?? schemaNameParts.ToArray();

            for (var i = 1; i < nameParts.Length; i++)
            {
                schemaName.Append(Inflector.MakeInitialUpperCase(nameParts[i]));
            }

            return(schemaName.ToString());
        }