Created
April 29, 2015 22:33
-
-
Save richlander/7ab29fe9ffa71eabe9be to your computer and use it in GitHub Desktop.
App Context Usage
This file contains 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
bool shouldThrow; | |
if (!AppContext.TryGetSwitch(“Switch.AmazingLib.ThrowOnException”, out shouldThrow)) | |
{ | |
// The switch value was not set by the application. | |
// As a result, the value is 'false'. A false value implies the latest behavior. | |
// The library can declare a default value for a switch based on a condition | |
// Example: https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/AppContext/AppContextDefaultValues.Defaults.cs | |
} | |
// The library can use the value of shouldThrow to throw exceptions or not. | |
if (shouldThrow) | |
{ | |
// old code | |
} | |
else | |
{ | |
//new code | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixing those curly-quotes on line #3 to straight ones: