Created
January 2, 2011 16:28
-
-
Save GraemeF/762627 to your computer and use it in GitHub Desktop.
SimpleValue
This file contains hidden or 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
public abstract class SimpleValue<TValue> | |
{ | |
private TValue _value; | |
protected SimpleValue(TValue value) | |
{ | |
Value = value; | |
} | |
private TValue Value | |
{ | |
get { return _value; } | |
set | |
{ | |
if (value == null) | |
throw new ArgumentNullException("Value"); | |
_value = value; | |
} | |
} | |
public static bool operator ==(SimpleValue<TValue> operand, SimpleValue<TValue> operand2) | |
{ | |
if (ReferenceEquals(operand, operand2)) | |
return true; | |
return !ReferenceEquals(null, operand) && operand.Equals(operand2); | |
} | |
public static bool operator !=(SimpleValue<TValue> operand, SimpleValue<TValue> operand2) | |
{ | |
return !(operand == operand2); | |
} | |
public override bool Equals(object obj) | |
{ | |
var other = obj as SimpleValue<TValue>; | |
return other != null && | |
GetType() == other.GetType() && | |
Value.Equals(other.Value); | |
} | |
public override int GetHashCode() | |
{ | |
return Value.GetHashCode(); | |
} | |
public override string ToString() | |
{ | |
return _value.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment