Created
April 14, 2013 08:48
-
-
Save jmhdez/5381986 to your computer and use it in GitHub Desktop.
Id implementation using phantom types
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
public struct Id<T> | |
{ | |
public readonly int Value; | |
public Id(int value) | |
{ | |
this.value = value; | |
} | |
public static implicit operator Id<T>(int value) | |
{ | |
return new Id<T>(value); | |
} | |
public override bool Equals(object obj) | |
{ | |
return obj is Id<T> && ((Id<T>) obj).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