Skip to content

Instantly share code, notes, and snippets.

@jsvnm
Created March 26, 2013 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsvnm/5248107 to your computer and use it in GitHub Desktop.
Save jsvnm/5248107 to your computer and use it in GitHub Desktop.
Why are the values in a box? come out of there.
private static class Boxed<T> {
internal static readonly Converter<object, T> PleaseComeOut = Boxed<T>.Delivers(typeof(T));
private static Converter<object, T> Delivers(Type type) {
if (type.IsValueType) return new Converter<object, T>(Boxed<T>.Contents);
throw new InvalidOperationException("No thanks");
}
private static T Contents(object value) { return (T) value; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment