Created
October 19, 2009 22:54
-
-
Save jcbozonier/213795 to your computer and use it in GitHub Desktop.
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 struct NotNull<T> where T : class | |
| { | |
| private readonly T _Value; | |
| private NotNull(T value) | |
| { | |
| if (value == null) | |
| throw new ArgumentNullException("value"); | |
| _Value = value; | |
| } | |
| public static explicit operator NotNull<T>(T value) | |
| { | |
| return new NotNull<T>(value); | |
| } | |
| public static explicit operator T(NotNull<T> value) | |
| { | |
| return value._Value; | |
| } | |
| public static bool operator ==(NotNull<T> obj1, NotNull<T> obj2) | |
| { | |
| return obj1.Equals(obj2); | |
| } | |
| public static bool operator !=(NotNull<T> obj1, NotNull<T> obj2) | |
| { | |
| return !(obj1 == obj2); | |
| } | |
| public override bool Equals(object obj) | |
| { | |
| if(obj is NotNull<T>) | |
| return Equals((NotNull<T>)obj); | |
| return _Value.Equals(obj); | |
| } | |
| public bool Equals(NotNull<T> other) | |
| { | |
| return Equals(other._Value, _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