Skip to content

Instantly share code, notes, and snippets.

@GeoffCox
Last active August 29, 2015 14:09
Show Gist options
  • Save GeoffCox/fcd338dd5e83ddac78d4 to your computer and use it in GitHub Desktop.
Save GeoffCox/fcd338dd5e83ddac78d4 to your computer and use it in GitHub Desktop.
Stop C# compiler from static type-checking
// Sometimes the compiler will try to statically type-check when you don't want it to.
// TODO: I need to get a better example in here.
// This extension method to object makes the static type checker give up through the use of a generic method that does the casting.
public static T CastAs<T>(this object value)
{
return (T)value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment