Skip to content

Instantly share code, notes, and snippets.

@jmillikan
Last active August 29, 2015 14:08
Show Gist options
  • Save jmillikan/650eb3ec66eebd4a7b8c to your computer and use it in GitHub Desktop.
Save jmillikan/650eb3ec66eebd4a7b8c to your computer and use it in GitHub Desktop.
class Error<T>
{
public Func<T> Unfetched = () => { throw new Exception("Unfetched"); };
}
static class Errors
{
public static Error<string> String = new Error<string>();
public static Error<float> Float = new Error<float>();
}
class Person {
public Func<string> Name = Errors.String.Unfetched;
public Func<float> Age = Errors.Float.Unfetched;
public Func<int, bool> FetchById;
public Person()
{
FetchById = (int id) =>
{
if (new Random().Next(0, 50) == 0)
{
Name = Errors.String.Unfetched;
Age = Errors.Float.Unfetched;
return false;
}
var dataRow = new { Age = 20, Name = "Joe Blow" };
Name = () => dataRow.Name;
Age = () => dataRow.Age;
return true;
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment