* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / corlib / System / Version.cs
index adc86fa5568d80388dc34abd1b376227d4dedfe9..69e47bd30d08211e3befcbfb9e81545e9c4d1334 100644 (file)
@@ -34,6 +34,9 @@ namespace System
 {
        [Serializable]
        public sealed class Version : ICloneable, IComparable
+#if NET_2_0
+               , IComparable<Version>, IEquatable <Version>
+#endif
        {
 
                int _Major, _Minor, _Build, _Revision;
@@ -162,16 +165,28 @@ namespace System
 
                public int CompareTo (object version)
                {
-                       Version v;
-
                        if (version == null)
                                return 1;
 
                        if (! (version is Version))
                                throw new ArgumentException (Locale.GetText ("Argument to Version.CompareTo must be a Version."));
 
-                       v = version as Version;
+                       return this.CompareTo ((Version) version);
+               }
+
+               public override bool Equals (object obj)
+               {
+                       return this.Equals (obj as Version);
+               }
 
+#if NET_2_0
+               public
+#endif
+               int CompareTo (Version v)
+               {
+                       if (v == null)
+                               return 1;
+                       
                        if (this._Major > v._Major)
                                return 1;
                        else if (this._Major < v._Major)
@@ -195,21 +210,16 @@ namespace System
                        return 0;
                }
 
-               public override bool Equals (object obj)
+#if NET_2_0
+               public
+#endif
+               bool Equals (Version x)
                {
-                       Version x;
-                       
-                       if (obj == null || !(obj is Version))
-                               return false;
-
-                       x = (Version) obj;
-                       
-                       if ((x._Major == _Major) &&
+                       return ((x != null) &&
+                           (x._Major == _Major) &&
                            (x._Minor == _Minor) &&
                            (x._Build == _Build) &&
-                           (x._Revision == _Revision))
-                               return true;
-                       return false;
+                           (x._Revision == _Revision));
                }
 
                public override int GetHashCode ()
@@ -307,6 +317,9 @@ namespace System
                        int state = 1;
                        int number = UNDEFINED; // string may not begin with a digit
 
+                        if (info == null)
+                                return new Version (0, 0, 0, 0);
+
                        for (int i=0; i < info.Length; i++) {
                                char c = info [i];
                                if (Char.IsDigit (c)) {
@@ -340,6 +353,24 @@ namespace System
                                if (state == 5)
                                        break;
                        }
+
+                       // Last number
+                       if (number >= 0) {
+                               switch (state) {
+                               case 1:
+                                       major = number;
+                                       break;
+                               case 2:
+                                       minor = number;
+                                       break;
+                               case 3:
+                                       build = number;
+                                       break;
+                               case 4:
+                                       revision = number;
+                                       break;
+                               }
+                       }
                        return new Version (major, minor, build, revision);
                }
        }