Skip to content

Instantly share code, notes, and snippets.

@jagregory
Created August 25, 2010 21:07
Show Gist options
  • Save jagregory/550294 to your computer and use it in GitHub Desktop.
Save jagregory/550294 to your computer and use it in GitHub Desktop.
// 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