Created
October 12, 2012 17:06
-
-
Save NeilRobbins/3880277 to your computer and use it in GitHub Desktop.
Type aliasing in C#
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> | |
/// Effectively an alias of string, but with a stronger semantic | |
/// </summary> | |
/// <remarks> | |
/// Can still pass it to something (eg a screen element, or a db, that expects a string), but get to call it | |
/// by a semantically richer type name everywhere, especially where it may be returned (returned things not | |
/// being named, except indirectly by the method name) | |
/// </remarks> | |
public class FooId | |
{ | |
private readonly string fooId; | |
public FooId(string fooId) | |
{ | |
this.fooId= fooId; | |
} | |
private string Id | |
{ | |
get { return fooId; } | |
} | |
public static implicit operator string(FooId fooId) | |
{ | |
return fooId.Id; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment