Last active
August 29, 2015 14:11
-
-
Save trapezoid/c6f0cae845ff62196454 to your computer and use it in GitHub Desktop.
ComparableValue
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
namespace Sample.ValueObject | |
{ | |
public abstract class ComparableValue<TConcrete> : IComparable<TConcrete> | |
where TConcrete : ComparableValue<TConcrete> | |
{ | |
#region IComparable implementation | |
public abstract int CompareTo(TConcrete other); | |
#endregion | |
public static bool operator > (ComparableValue<TConcrete> leftHand, ComparableValue<TConcrete> rightHand) { | |
return (leftHand as TConcrete).CompareTo(rightHand as TConcrete) > 0; | |
} | |
public static bool operator >= (ComparableValue<TConcrete> leftHand, ComparableValue<TConcrete> rightHand) | |
{ | |
return (leftHand as TConcrete).CompareTo(rightHand as TConcrete) >= 0; | |
} | |
public static bool operator < (ComparableValue<TConcrete> leftHand, ComparableValue<TConcrete> rightHand) | |
{ | |
return (leftHand as TConcrete).CompareTo(rightHand as TConcrete) < 0; | |
} | |
public static bool operator <= (ComparableValue<TConcrete> leftHand, ComparableValue<TConcrete> rightHand) | |
{ | |
return (leftHand as TConcrete).CompareTo(rightHand as TConcrete) <= 0; | |
} | |
} | |
public class SimpleValue : ComparableValue<SimpleValue> | |
{ | |
public int Value { get; private set; } | |
public SimpleValue(int value) { Value = value; } | |
#region IComparable implementation | |
public override int CompareTo(SimpleValue other) | |
{ | |
return Value.CompareTo(other.Value); | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment