Skip to content

Instantly share code, notes, and snippets.

@jmhdez
Created April 14, 2013 08:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jmhdez/5381986 to your computer and use it in GitHub Desktop.
Save jmhdez/5381986 to your computer and use it in GitHub Desktop.
Id implementation using phantom types
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