Clean up: Bugs, LINQ, constructors, default values, and null checks (#18)
This commit is contained in:
parent
e748af4430
commit
513e54f70e
1094 changed files with 15913 additions and 21892 deletions
|
|
@ -19,7 +19,7 @@
|
|||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Server
|
||||
|
|
@ -32,13 +32,9 @@ namespace Server
|
|||
SA
|
||||
}
|
||||
|
||||
public class ClientVersion : IComparable, IComparer
|
||||
public class ClientVersion : IComparable<ClientVersion>, IComparer<ClientVersion>
|
||||
{
|
||||
public ClientVersion(int maj, int min, int rev, int pat) : this(maj, min, rev, pat, ClientType.Regular)
|
||||
{
|
||||
}
|
||||
|
||||
public ClientVersion(int maj, int min, int rev, int pat, ClientType type)
|
||||
public ClientVersion(int maj, int min, int rev, int pat, ClientType type = ClientType.Regular)
|
||||
{
|
||||
Major = maj;
|
||||
Minor = min;
|
||||
|
|
@ -111,15 +107,10 @@ namespace Server
|
|||
|
||||
public string SourceString{ get; }
|
||||
|
||||
public int CompareTo(object obj)
|
||||
public int CompareTo(ClientVersion o)
|
||||
{
|
||||
if (obj == null)
|
||||
return 1;
|
||||
|
||||
ClientVersion o = obj as ClientVersion;
|
||||
|
||||
if (o == null)
|
||||
throw new ArgumentException();
|
||||
return 1;
|
||||
|
||||
if (Major > o.Major)
|
||||
return 1;
|
||||
|
|
@ -140,24 +131,6 @@ namespace Server
|
|||
return 0;
|
||||
}
|
||||
|
||||
public int Compare(object x, object y)
|
||||
{
|
||||
if (IsNull(x) && IsNull(y))
|
||||
return 0;
|
||||
if (IsNull(x))
|
||||
return -1;
|
||||
if (IsNull(y))
|
||||
return 1;
|
||||
|
||||
ClientVersion a = x as ClientVersion;
|
||||
ClientVersion b = y as ClientVersion;
|
||||
|
||||
if (IsNull(a) || IsNull(b))
|
||||
throw new ArgumentException();
|
||||
|
||||
return a.CompareTo(b);
|
||||
}
|
||||
|
||||
public static bool operator ==(ClientVersion l, ClientVersion r)
|
||||
{
|
||||
return Compare(l, r) == 0;
|
||||
|
|
@ -188,9 +161,14 @@ namespace Server
|
|||
return Compare(l, r) < 0;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
// public override int GetHashCode()
|
||||
// {
|
||||
// return Major ^ Minor ^ Revision ^ Patch ^ (int)Type;
|
||||
// }
|
||||
|
||||
int IComparer<ClientVersion>.Compare(ClientVersion x, ClientVersion y)
|
||||
{
|
||||
return Major ^ Minor ^ Revision ^ Patch ^ (int)Type;
|
||||
return Compare(x, y);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
|
|
@ -262,4 +240,4 @@ namespace Server
|
|||
return a.CompareTo(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue