Last active
August 29, 2015 14:09
-
-
Save GeoffCox/fcd338dd5e83ddac78d4 to your computer and use it in GitHub Desktop.
Stop C# compiler from static type-checking
This file contains hidden or 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
// 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