Created
April 8, 2011 07:03
-
-
Save masaedw/909423 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
| /// <summary> | |
| /// コンテナのキー等で型の別名を定義したいときに使うクラス | |
| /// </summary> | |
| /// <typeparam name="T"></typeparam> | |
| public class NewType<T> : IEquatable<NewType<T>> | |
| { | |
| /// <summary> | |
| /// 生の値を取得します | |
| /// </summary> | |
| public T Value { get; private set; } | |
| public NewType(T i) | |
| { | |
| Value = i; | |
| } | |
| /// <summary> | |
| /// 値を作成します | |
| /// </summary> | |
| /// <param name="i"></param> | |
| /// <returns></returns> | |
| public static NewType<T> Create(T i) | |
| { | |
| return new NewType<T>(i); | |
| } | |
| #region コンテナに入れたときにTと同様に動作するための準備 | |
| public override bool Equals(object obj) | |
| { | |
| if (obj == null) | |
| { | |
| return false; | |
| } | |
| var id = obj as NewType<T>; | |
| if ((object)id == null) | |
| { | |
| return false; | |
| } | |
| return this.Value.Equals(id.Value); | |
| } | |
| public override int GetHashCode() | |
| { | |
| return this.Value.GetHashCode(); | |
| } | |
| public static bool operator ==(NewType<T> a, NewType<T> b) | |
| { | |
| if (Object.ReferenceEquals(a, b)) | |
| { | |
| return true; | |
| } | |
| if (((object)a == null) || ((object)b == null)) | |
| { | |
| return false; | |
| } | |
| return a.Value.Equals(b.Value); | |
| } | |
| public static bool operator !=(NewType<T> a, NewType<T> b) | |
| { | |
| return !(a == b); | |
| } | |
| #region IEquatable<NewType<T>> メンバー | |
| public bool Equals(NewType<T> other) | |
| { | |
| return this.Value.Equals(other.Value); | |
| } | |
| #endregion | |
| #endregion | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment