Exemplo n.º 1
0
        public static int ComparePreRelease(PreReleaseVersion left, PreReleaseVersion right)
        {
            //if (ReferenceEquals(left, null)) throw new ArgumentNullException("Left operand can't be null.");
            //if (ReferenceEquals(right, null)) throw new ArgumentNullException("Right operand can't be null.");
            if (ReferenceEquals(left, right))
            {
                return(0);
            }
            else if (ReferenceEquals(left, null) && !ReferenceEquals(right, null) && right.Count == 0)
            {
                return(0);
            }
            else if (ReferenceEquals(left, null) && !ReferenceEquals(right, null) && right.Count > 0)
            {
                return(1);
            }
            else if (ReferenceEquals(right, null) && !ReferenceEquals(left, null) && left.Count == 0)
            {
                return(0);
            }
            else if (ReferenceEquals(right, null) && !ReferenceEquals(left, null) && left.Count > 0)
            {
                return(-1);
            }

            for (int i = 0; i < Math.Min(left.Count, right.Count); i++)
            {
                var ac = left[i];
                var bc = right[i];
                int anum, bnum;
                var isanum = Int32.TryParse(ac, out anum);
                var isbnum = Int32.TryParse(bc, out bnum);
                int r;
                if (isanum && isbnum)
                {
                    r = anum.CompareTo(bnum);
                    if (r != 0)
                    {
                        return(anum.CompareTo(bnum));
                    }
                }
                else
                {
                    if (isanum)
                    {
                        return(-1);
                    }
                    if (isbnum)
                    {
                        return(1);
                    }
                    r = String.CompareOrdinal(ac, bc);
                    if (r != 0)
                    {
                        return(r);
                    }
                }
            }
            return(left.Count.CompareTo(right.Count));
        }
Exemplo n.º 2
0
        public int CompareTo(SemanticVersion other)
        {
            if (Object.ReferenceEquals(other, null))
            {
                return(1);
            }

            int result = this.SystemVersion.CompareTo(other.SystemVersion);

            if (result != 0)
            {
                return(result);
            }

            bool empty      = ReferenceEquals(PreRelease, null);
            bool otherEmpty = ReferenceEquals(other.PreRelease, null);;

            if (empty && otherEmpty)
            {
                return(0);
            }
            else if (empty)
            {
                return(1);
            }
            else if (otherEmpty)
            {
                return(-1);
            }
            else
            {
                return(PreReleaseVersion.ComparePreRelease(PreRelease, other.PreRelease));
            }
        }
Exemplo n.º 3
0
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(obj, null))
            {
                return(false);
            }
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }
            PreReleaseVersion other = (PreReleaseVersion)obj;

            return(ComparePreRelease(this, other) == 0);
        }