Created
August 25, 2010 21:07
-
-
Save jagregory/550294 to your computer and use it in GitHub Desktop.
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
// boom | |
public class Ex | |
{ | |
public static readonly Ex Foo = Parse('f'); | |
public static readonly Ex Bar = Parse('b'); | |
Dictionary<char, string> validValues = new Dictionary<char, string> | |
{ | |
{ 'f', "Foo" }, | |
{ 'b', "Bar" }, | |
}; | |
static Ex Parse(char value) | |
{ | |
if (!validValues.ContainsKey(value)) | |
throw new InvalidOperationException("Bad value"); | |
return new Ex(value); | |
} | |
char value; | |
private Ex(char value) | |
{ | |
this.value = value; | |
} | |
} | |
// fine :) | |
public class Ex | |
{ | |
Dictionary<char, string> validValues = new Dictionary<char, string> | |
{ | |
{ 'f', "Foo" }, | |
{ 'b', "Bar" }, | |
}; | |
public static readonly Ex Foo = Parse('f'); | |
public static readonly Ex Bar = Parse('b'); | |
static Ex Parse(char value) | |
{ | |
if (!validValues.ContainsKey(value)) | |
throw new InvalidOperationException("Bad value"); | |
return new Ex(value); | |
} | |
char value; | |
private Ex(char value) | |
{ | |
this.value = value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment