public static ITextFormatter GetTextFormatter(ApplicationPreferences applicationPreferences)
        {
            ITextFormatter formatter;

            switch (applicationPreferences.FieldNamingConvention)
            {
            case FieldNamingConvention.SameAsDatabase:
                formatter = new UnformattedTextFormatter();
                break;

            case FieldNamingConvention.CamelCase:
                formatter = new CamelCaseTextFormatter();
                break;

            case FieldNamingConvention.PascalCase:
                formatter = new PascalCaseTextFormatter();
                break;

            case FieldNamingConvention.Prefixed:
                formatter = new PrefixedTextFormatter(applicationPreferences.Prefix);
                break;

            default:
                throw new Exception("Invalid or unsupported field naming convention.");
            }

            formatter.PrefixRemovalList = applicationPreferences.FieldPrefixRemovalList;

            return(formatter);
        }
Esempio n. 2
0
        public void CamelCaseSingular()
        {
            var formatter = new CamelCaseTextFormatter();

            Assert.AreEqual("columnName", formatter.FormatSingular("Column_Name"));
            Assert.AreEqual("columnName", formatter.FormatSingular("COLUMN_NAME"));
        }
 public void CamelCasePlural()
 {
     var formatter = new CamelCaseTextFormatter();
     Inflector.EnableInflection = true;
     Assert.AreEqual("columnNames", formatter.FormatPlural("Column_Name"));
     Assert.AreEqual("columnNames", formatter.FormatPlural("COLUMN_NAME"));
 }
Esempio n. 4
0
        public void ConvertStringToCamelCase()
        {
            var formatter = new CamelCaseTextFormatter();

            Assert.AreEqual("columnName", formatter.FormatText("Column_Name"));
            Assert.AreEqual("columnName", formatter.FormatText("COLUMN_NAME"));
            Assert.AreEqual("hitMan", formatter.FormatText("HitMan"));
        }
Esempio n. 5
0
        private void CreateFullProperties(CodeGenerationHelper codeGenerationHelper, DataTypeMapper mapper, CodeTypeDeclaration newType)
        {
            var camelCaseFormatter = new CamelCaseTextFormatter();
            if (Table.PrimaryKey != null)
            {

                foreach (var pk in Table.PrimaryKey.Columns)
                {
                    if (pk.IsForeignKey && appPrefs.IncludeForeignKeys)
                    {
                        newType.Members.Add(codeGenerationHelper.CreateField(Formatter.FormatSingular(pk.ForeignKeyTableName), "_" + camelCaseFormatter.FormatSingular(pk.ForeignKeyTableName)));
                        newType.Members.Add(codeGenerationHelper.CreateProperty(Formatter.FormatSingular(pk.ForeignKeyTableName), Formatter.FormatSingular(pk.ForeignKeyTableName), appPrefs.UseLazy));
                    }
                    else
                    {
                        var mapFromDbType = mapper.MapFromDBType(appPrefs.ServerType, pk.DataType, pk.DataLength, pk.DataPrecision, pk.DataScale);

                        var pkAlsoFkQty = (from fk in Table.ForeignKeys.Where(fk => fk.UniquePropertyName == pk.Name) select fk).Count();
                        var fieldName = FixPropertyWithSameClassName(pk.Name, Table.Name);
                        if (pkAlsoFkQty > 0)
                        {
                            fieldName = fieldName + "Id";
                        }
                        newType.Members.Add(codeGenerationHelper.CreateField(mapFromDbType, "_" + camelCaseFormatter.FormatText(fieldName), true));
                        newType.Members.Add(codeGenerationHelper.CreateProperty(mapFromDbType, Formatter.FormatText(fieldName), appPrefs.UseLazy));
                    }
                }
            }

            if (appPrefs.IncludeForeignKeys)
            {
                var pascalCaseTextFormatter = new PascalCaseTextFormatter { PrefixRemovalList = appPrefs.FieldPrefixRemovalList };
                // Note that a foreign key referencing a primary within the same table will end up giving you a foreign key property with the same name as the table.
                foreach (var fk in Table.Columns.Where(c => c.IsForeignKey && !c.IsPrimaryKey))
                {
                    var typeName = appPrefs.ClassNamePrefix + pascalCaseTextFormatter.FormatSingular(fk.ForeignKeyTableName);
                    var propertyName = fk.ForeignKeyTableName;
                    var fieldName = FixPropertyWithSameClassName(propertyName, Table.Name);

                    newType.Members.Add(codeGenerationHelper.CreateField(typeName, string.Format("_{0}", camelCaseFormatter.FormatSingular(fieldName))));
                    newType.Members.Add(codeGenerationHelper.CreateProperty(typeName, Formatter.FormatSingular(fieldName), appPrefs.UseLazy));
                }
            }

            foreach (var column in Table.Columns.Where(x => !x.IsPrimaryKey && (!x.IsForeignKey || !appPrefs.IncludeForeignKeys)))
            {
                var mapFromDbType = mapper.MapFromDBType(appPrefs.ServerType, column.DataType, column.DataLength, column.DataPrecision, column.DataScale);
                var fieldName = FixPropertyWithSameClassName(column.Name, Table.Name);
                newType.Members.Add(codeGenerationHelper.CreateField(mapFromDbType, "_" + camelCaseFormatter.FormatText(fieldName), column.IsNullable));

                var property = codeGenerationHelper.CreateProperty(mapFromDbType, Formatter.FormatText(fieldName), column.IsNullable, appPrefs.UseLazy);
                AttachValidatorAttributes(ref property, column);
                newType.Members.Add(property);
            }
        }
Esempio n. 6
0
        public static ITextFormatter GetTextFormatter(ApplicationPreferences applicationPreferences)
        {
            ITextFormatter formatter;
            switch(applicationPreferences.FieldNamingConvention)
            {
                case FieldNamingConvention.SameAsDatabase:
                    formatter = new UnformattedTextFormatter();
                    break;
                case FieldNamingConvention.CamelCase:
                    formatter = new CamelCaseTextFormatter();
                    break;
                case FieldNamingConvention.PascalCase:
                    formatter = new PascalCaseTextFormatter();
                    break;
                case FieldNamingConvention.Prefixed:
                    formatter = new PrefixedTextFormatter(applicationPreferences.Prefix);
                    break;
                default:
                    throw new Exception("Invalid or unsupported field naming convention.");
            }

            formatter.PrefixRemovalList = applicationPreferences.FieldPrefixRemovalList;

            return formatter;
        }