Skip to content

Instantly share code, notes, and snippets.

@jmhdez
Created Apr 14, 2013
Embed
What would you like to do?
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