tools/VsIdeHostAdapter/TargetAddIn/Common/VsVersionComparer.cs
/// <summary>
/// Compares VS Versions, such as 9.0 to 10.1 using number comparison. 
/// The arguments must match VsVersionRegex. If they do not, the method does string comparison.
/// Anyhow, if there's any error to parse the number, the method does string comparison.
/// </summary>
Compares VS Versions, such as 9.0 to 10.1 using number comparison.
The arguments must match VsVersionRegex. If they do not, the method does string comparison.
Anyhow, if there's any error to parse the number, the method does string comparison.
Compares VS Versions such as 9 . 0 to 10 . 1 using number comparison . The arguments must match VsVersionRegex . If they do not the method does string comparison . Anyhow if there ' s any error to parse the number the method does string comparison .
public int Compare(string x, string y)
        {
            if (x == null || y == null ||
                !VsVersionRegex.Match(x).Success || !VsVersionRegex.Match(y).Success)
            {
                return s_stringComparer.Compare(x, y);
            }
            string[] xParts = x.Split(new char[] { '.' }, StringSplitOptions.None);
            string[] yParts = y.Split(new char[] { '.' }, StringSplitOptions.None);
            if (xParts.Length != yParts.Length)
            {
                return s_stringComparer.Compare(x, y);
            }
            try
            {
                for (int i = 0; i < xParts.Length; ++i)
                {
                    int xPart = int.Parse(xParts[i], NumberStyles.None, CultureInfo.InvariantCulture);
                    int yPart = int.Parse(yParts[i], NumberStyles.None, CultureInfo.InvariantCulture);
                    if (xPart != yPart)
                    {
                        return xPart < yPart ? -1 : 1;
                    }
                }
            }
            catch (SystemException)
            {
                return s_stringComparer.Compare(x, y);
            }
            return 0;
        }
public int Compare ( string x , string y ) { if ( x == null || y == null || ! VsVersionRegex . Match ( x ) . Success || ! VsVersionRegex . Match ( y ) . Success ) { return s_stringComparer . Compare ( x , y ) ; } string [ ] xParts = x . Split ( new char [ ] { ' ' } , StringSplitOptions . None ) ; string [ ] yParts = y . Split ( new char [ ] { ' ' } , StringSplitOptions . None ) ; if ( xParts . Length != yParts . Length ) { return s_stringComparer . Compare ( x , y ) ; } try { for ( int i = 0 ; i < xParts . Length ; ++ i ) { int xPart = int . Parse ( xParts [ i ] , NumberStyles . None , CultureInfo . InvariantCulture ) ; int yPart = int . Parse ( yParts [ i ] , NumberStyles . None , CultureInfo . InvariantCulture ) ; if ( xPart != yPart ) { return xPart < yPart ? - 1 : 1 ; } } } catch ( SystemException ) { return s_stringComparer . Compare ( x , y ) ; } return 0 ; }
Compares VS Versions, such as 9.0 to 10.1 using number comparison.
Compares VS Versions such as 9 . 0 to 10 . 1 using number comparison .
x
string
y
string