private static void Migrate(UnigrationNode old, UnigrationNode to) { if (!to.IsGreaterThan(old)) { Debug.Log("Migrate(Skipped) " + old.version + " -> " + to.version); return; } Debug.Log("Migrate " + old.version + " -> " + to.version); var types = typeof(AssemblyTag).Assembly.GetExportedTypes() .Concat(Assembly.GetExecutingAssembly().GetTypes()); foreach (var type in types) { if (type.Namespace != old.container) { continue; } var md = new Regex("^[a-zA-Z]+_([0-9_]+)$").Match(type.Name); if (md.Groups.Count == 1) { Debug.Log("Malformed migration script : " + type.Namespace + "::" + type.Name); continue; } var version = md.Groups[1].Value.Replace('_', '.'); var up = type.GetMethod("Up"); var since = type.GetMethod("Since"); if (to.IsGEThan(version)) { if (since != null) { since.Invoke(null, new object[] { old.version }); } } if (to.version == version) { if (up != null) { up.Invoke(null, new object[] { old.version }); } } } }
public bool IsGEThan(UnigrationNode o) { return(new Version(version) >= new Version(o.version)); }
public bool IsGreaterThan(UnigrationNode o) { return(new Version(version) > new Version(o.version)); }