コード例 #1
0
ファイル: TypeToEntity.cs プロジェクト: pingvinen/worm
 protected void AddProperties(PocoEntity result, WType type)
 {
     PropertyToPocoField converter = this.factory.GetPropertyToPocoField();
     foreach (WProperty property in type.GetProperties())
     {
         if (property.GetAttribute<WormIgnoreAttribute>() == default(WormIgnoreAttribute))
         {
             result.Fields.Add(converter.Parse(property));
         }
     }
 }
コード例 #2
0
        public void Test()
        {
            var dbClassWriter = new DbClassWriter(new WormFactory());
            var entity = new PocoEntity() {
                DbFactory = new MySqlWormDbFactory(String.Empty),
                PocoClassName = "TestEntity",
                PocoFilename = "TestEntity.cs",
                PocoNamespace = "Test.Entities",
                TableName = "test_entities",
                WormClassName = "WormTestEntity",
                WormFilename = "WormTestEntity.cs",
                WormNamespace = "Test.Entities.Db"
            };

            entity.Fields.Add(new PocoField() {
                AccessModifier = AccessModifier.Public,
                ColumnName = "id",
                HasGetter = true,
                HasSetter = true,
                IdGenerator = WormIdGenerator.AutoIncrement,
                IsPrimaryKey = true,
                Name = "Id",
                StorageType = "int",
                Type = "int"
            });

            entity.Fields.Add(new PocoField() {
                AccessModifier = AccessModifier.Public,
                ColumnName = "my_string",
                HasGetter = true,
                HasSetter = true,
                Name = "MyString",
                StorageType = "varchar(255)",
                Type = "string"
            });

            entity.Fields.Add(new PocoField() {
                AccessModifier = AccessModifier.Public,
                ColumnName = "my_int",
                HasGetter = true,
                HasSetter = true,
                Name = "MyInt",
                StorageType = "int",
                Type = "int"
            });

            var result = dbClassWriter.Generate(entity);

            System.IO.File.WriteAllText("/tmp/mysql_" + result.Filename, result.Content);

            Assert.AreEqual("WormTestEntity.cs", result.Filename);
        }
コード例 #3
0
ファイル: DbClassWriter.cs プロジェクト: pingvinen/worm
        public CodeFile Generate(PocoEntity model)
        {
            var template = this.factory.GetWormDbClassTemplate();
            template.Model = model;

            var provider = model.DbFactory.GetTemplateProvider();

            template.DbGetByIdOrDefaultTemplate = provider.GetDbGetByIdOrDefaultTemplate();
            template.DbGetByIdOrDefaultTemplate.Poco = model;

            template.DbInsertTemplate = provider.GetDbInsertTemplate();
            template.DbInsertTemplate.Poco = model;

            template.DbUpdateTemplate = provider.GetDbUpdateTemplate();
            template.DbUpdateTemplate.Poco = model;

            return new CodeFile() {
                Filename = model.WormFilename,
                Content = template.TransformText()
            };
        }