public static IMigrationInfo GetMigrationInfoFor(Type migrationType)
        {
            var migrationAttribute = migrationType.GetOneAttribute<MigrationAttribute>();
            Func<IMigration> migrationFunc = () => (IMigration)migrationType.Assembly.CreateInstance(migrationType.FullName);
            var migrationInfo = new MigrationInfo(migrationAttribute.Version, migrationAttribute.Description, migrationAttribute.TransactionBehavior, migrationFunc);

            foreach (MigrationTraitAttribute traitAttribute in migrationType.GetAllAttributes<MigrationTraitAttribute>())
                migrationInfo.AddTrait(traitAttribute.Name, traitAttribute.Value);

            return migrationInfo;
        }
        public static IMigrationInfo GetMigrationInfoFor(IMigration migration)
        {
            var migrationAttribute = migration.GetType().GetOneAttribute<MigrationAttribute>();
            var migrationInfo = new MigrationInfo(migrationAttribute.Version, migrationAttribute.TransactionBehavior, migration);

            foreach (MigrationTraitAttribute traitAttribute in migration.GetType().GetAllAttributes<MigrationTraitAttribute>())
                migrationInfo.AddTrait(traitAttribute.Name, traitAttribute.Value);

            return migrationInfo;
        }
Ejemplo n.º 3
0
            private static IMigrationInfo GetMigrationInfoFor(FluentMigrator.IMigration migration)
            {
                var migrationType = migration.GetType();
                var migrationAttribute = migrationType.GetOneAttribute<MigrationAttribute>();
                var chunSunMigration = migration as MigrationBase;
                if (chunSunMigration == null)
                    throw new Exception("迁移提供程序必须继承自 \"" + typeof(MigrationBase).FullName + "\" 类型。");
                var id = chunSunMigration.Feature.Descriptor.Id;

                var version = migrationAttribute.Version;
                var description = id + "_" + migrationAttribute.Description + "_" + migrationAttribute.Version;

                var migrationInfo = new MigrationInfo(version, description, migrationAttribute.TransactionBehavior, () => migration);
                var allAttributes = migrationType.GetAllAttributes<MigrationTraitAttribute>();
                foreach (var traitAttribute in allAttributes)
                    migrationInfo.AddTrait(traitAttribute.Name, traitAttribute.Value);
                return migrationInfo;
            }