private List <MethodInfo> GetMethods(DataMigration migration, int version, int endVersion = 0, bool isUp = true) { var methodHeader = isUp ? "Up" : "Down"; var methods = migration .GetType() .GetRuntimeMethods() .Where( m => m.IsPublic && m.ReturnType == typeof(void) && m.Name.StartsWith(methodHeader, StringComparison.OrdinalIgnoreCase)) .Select( m => new MethodInfo { Version = Convert.ToInt32(m.Name.Substring(methodHeader.Length)) + 1, Method = builder => m.Invoke(migration, new[] { builder }) }) .Where(method => method.Version > version && method.Version < endVersion); if (isUp) { return(methods.OrderBy(method => method.Version).ToList()); } return(methods.OrderByDescending(method => method.Version).ToList()); }
private IEnumerable <OperationsMigration> Upgrade(DataMigration migration, Migration dbMigration, int version) { var id = migration.GetType().FullName; if (dbMigration == null) { yield return(CreateOperationsMigration(id, 1, migration.Create)); } var methods = GetMethods(migration, dbMigration?.Version ?? 0, version); foreach (var method in methods) { yield return(CreateOperationsMigration(id, method.Version, method.Method)); } }