Created
June 1, 2012 11:11
-
-
Save mabster/2851282 to your computer and use it in GitHub Desktop.
IComparable with Fody?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// before | |
public class Foo : IComparable<Foo> | |
{ | |
int Id { get; set; } | |
public int CompareTo(Foo other) | |
{ | |
if (other == null) return -1; | |
return this.Id.CompareTo(other.Id); | |
} | |
} | |
// after | |
public class Foo : IComparable<Foo>, IComparable | |
{ | |
int Id { get; set; } | |
public int CompareTo(Foo other) | |
{ | |
if (other == null) return 1; | |
return this.Id.CompareTo(other.Id); | |
} | |
public int CompareTo(object obj) | |
{ | |
if (obj == null) return 1; | |
var foo = obj as Foo; | |
if (foo == null) throw new ArgumentException("Object is not of type " + this.GetType()); | |
return this.CompareTo(foo); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment