* Version.cs (CompareTo, Equals): Make sure the versions for
authorBen Maurer <benm@mono-cvs.ximian.com>
Sat, 12 Feb 2005 18:58:05 +0000 (18:58 -0000)
committerBen Maurer <benm@mono-cvs.ximian.com>
Sat, 12 Feb 2005 18:58:05 +0000 (18:58 -0000)
generics handle `null'. The non-generics versions now just call
the regular versions, to reduce code duplication.

svn path=/trunk/mcs/; revision=40546

mcs/class/corlib/System/ChangeLog
mcs/class/corlib/System/Version.cs

index c14f6508656e7d37e780785452140d3497a2bc38..0a5517c2d9188c321e98f29fbb7a02492886f04d 100644 (file)
@@ -1,5 +1,9 @@
 2005-02-12  Ben Maurer  <bmaurer@ximian.com>
 
+       * Version.cs (CompareTo, Equals): Make sure the versions for
+       generics handle `null'. The non-generics versions now just call
+       the regular versions, to reduce code duplication.
+
        * Boolean.cs (CompareTo): make this really work for generics 
 
        * Type.cs (GetProperty): Passing new Type [0] is different than
index 2a3b7e7b95991bc54c3a0c1e6fd3800b4a791491..8835e5e6edd35213add4cedbb8e09944db7d9b06 100644 (file)
@@ -167,59 +167,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;
-
-                       if (this._Major > v._Major)
-                               return 1;
-                       else if (this._Major < v._Major)
-                               return -1;
-
-                       if (this._Minor > v._Minor)
-                               return 1;
-                       else if (this._Minor < v._Minor)
-                               return -1;
-
-                       if (this._Build > v._Build)
-                               return 1;
-                       else if (this._Build < v._Build)
-                               return -1;
-
-                       if (this._Revision > v._Revision)
-                               return 1;
-                       else if (this._Revision < v._Revision)
-                               return -1;
-
-                       return 0;
+                       return this.CompareTo ((Version) version);
                }
 
                public override bool Equals (object obj)
                {
-                       Version x;
-                       
-                       if (obj == null || !(obj is Version))
-                               return false;
-
-                       x = (Version) obj;
-                       
-                       if ((x._Major == _Major) &&
-                           (x._Minor == _Minor) &&
-                           (x._Build == _Build) &&
-                           (x._Revision == _Revision))
-                               return true;
-                       return false;
+                       return this.Equals (obj as Version);
                }
 
 #if NET_2_0
-               public int CompareTo (Version v)
+               public
+#endif
+               int CompareTo (Version v)
                {
+                       if (v == null)
+                               return 1;
+                       
                        if (this._Major > v._Major)
                                return 1;
                        else if (this._Major < v._Major)
@@ -243,16 +212,17 @@ namespace System
                        return 0;
                }
 
-               public bool Equals (Version x)
+#if NET_2_0
+               public
+#endif
+               bool Equals (Version x)
                {
-                       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));
                }
-#endif
 
                public override int GetHashCode ()
                {