Skip to content

Instantly share code, notes, and snippets.

@GraemeF
Created January 2, 2011 16:28
Show Gist options
  • Save GraemeF/762627 to your computer and use it in GitHub Desktop.
Save GraemeF/762627 to your computer and use it in GitHub Desktop.
SimpleValue
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