Skip to content

Commit e3882a2

Browse files
author
Lamond Lu
committed
add icomparer for version
1 parent 44686e2 commit e3882a2

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

DynamicPlugins.Core/DomainModel/PluginPackage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public List<IMigration> GetAllMigrations(string connectionString)
5151

5252
assembly = null;
5353

54-
return migrations;
54+
return migrations.OrderBy(p => p.Version).ToList();
5555
}
5656

5757
public void Initialize(Stream stream)

DynamicPlugins.Core/DomainModel/Version.cs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,55 @@
44

55
namespace DynamicPlugins.Core.DomainModel
66
{
7-
public class Version
7+
public class Version : IComparer<Version>
88
{
99
public Version(string versionNumber)
1010
{
1111
this.VersionNumber = versionNumber;
1212
}
1313

14+
public int PrimaryVersion
15+
{
16+
get
17+
{
18+
return Convert.ToInt32(this.VersionNumber.Split('.')[0]);
19+
}
20+
}
21+
22+
public int SecondaryVersion
23+
{
24+
get
25+
{
26+
return Convert.ToInt32(this.VersionNumber.Split('.')[1]);
27+
}
28+
}
29+
30+
public int MinorVersion
31+
{
32+
get
33+
{
34+
return Convert.ToInt32(this.VersionNumber.Split('.')[2]);
35+
}
36+
}
37+
1438
public string VersionNumber { get; set; }
1539

40+
public int Compare(Version x, Version y)
41+
{
42+
if (x.PrimaryVersion > y.PrimaryVersion || (x.PrimaryVersion == y.PrimaryVersion && x.SecondaryVersion > y.SecondaryVersion) || (x.PrimaryVersion == y.PrimaryVersion && x.SecondaryVersion == y.SecondaryVersion && x.MinorVersion > y.MinorVersion))
43+
{
44+
return 1;
45+
}
46+
else if (x.PrimaryVersion == y.PrimaryVersion && x.SecondaryVersion == y.SecondaryVersion && x.MinorVersion == y.MinorVersion)
47+
{
48+
return 0;
49+
}
50+
else
51+
{
52+
return -1;
53+
}
54+
}
55+
1656
public static bool operator ==(Version left, Version right)
1757
{
1858
if (left == null || right == null)

0 commit comments

Comments
 (0)