예제 #1
0
        public Type CreateType(TableMeta table)
        {
            var builder = DynamicAssembly.BuildClass(table.Name)
                          .WithAttribute(() => new DbTableAttribute(table.Name))
                          .WithAttribute <SerializableAttribute>();

            foreach (var column in table.Columns)
            {
                builder.AddProperty(column.Name, column.CSharpType);
            }

            var type = builder.CreateType();

            return(type);
        }
예제 #2
0
        public void Should()
        {
            var assembly = new DynamicAssembly("noe");
            var type     = assembly.BuildClass("Hest").WithAttribute <SerializableAttribute>().CreateType();


            var setup = new AppDomainSetup {
                ApplicationBase = Environment.CurrentDirectory
            };
            var domain = AppDomain.CreateDomain("Stuff", null, setup);

            Show(domain);
            domain.Load(assembly.GetBytes());

            var hest = domain.CreateInstanceAndUnwrap(type.Assembly.FullName, type.FullName);
        }
        public DynamicAssembly CreateFor(DatabaseSchema schema)
        {
            var assembly = new DynamicAssembly(schema.FullName);

            foreach (var table in schema.Tables)
            {
                var builder = assembly.BuildClass(Typify(table.Name))
                              .WithAttribute <SerializableAttribute>()
                              .WithAttribute(() => new DbTableAttribute(table.Name));
                foreach (var column in table.Columns)
                {
                    builder.WithProperty(Typify(column.Name), column.CSharpType, b => b
                                         .WithGetter()
                                         .WithSetter()
                                         .WithAttribute(() => new DbColumnAttribute(column.Name, column.Type, column.IsNullable, column.IsPrimaryKey)));
                }
                builder.CreateType();
            }
            return(assembly);
        }