Merge branch 'BigIntegerParse'
[mono.git] / mcs / class / dlr / Runtime / Microsoft.Dynamic / DebugOptions.cs
1 /* ****************************************************************************
2  *
3  * Copyright (c) Microsoft Corporation. 
4  *
5  * This source code is subject to terms and conditions of the Apache License, Version 2.0. A 
6  * copy of the license can be found in the License.html file at the root of this distribution. If 
7  * you cannot locate the  Apache License, Version 2.0, please send an email to 
8  * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
9  * by the terms of the Apache License, Version 2.0.
10  *
11  * You must not remove this notice, or any other, from this software.
12  *
13  *
14  * ***************************************************************************/
15
16 using System.Security;
17 using System;
18
19 namespace Microsoft.Scripting {
20
21     /// <summary>
22     /// This class holds onto internal debugging options used in this assembly. 
23     /// These options can be set via environment variables DLR_{option-name}.
24     /// Boolean options map "true" to true and other values to false.
25     /// 
26     /// These options are for internal debugging only, and should not be
27     /// exposed through any public APIs.
28     /// </summary>
29     internal static class DebugOptions {
30
31         private static bool ReadOption(string name) {
32 #if SILVERLIGHT
33             return false;
34 #else
35             string envVar = ReadString(name);
36             return envVar != null && envVar.ToLowerInvariant() == "true";
37 #endif
38         }
39
40         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "name")]
41         private static bool ReadDebugOption(string name) {
42 #if DEBUG
43             return ReadOption(name);
44 #else
45             return false;
46 #endif
47         }
48
49         private static string ReadString(string name) {
50 #if FEATURE_PROCESS
51             try {
52                 return Environment.GetEnvironmentVariable("DLR_" + name);
53             } catch (SecurityException) {
54                 return null;
55             }
56 #else
57             return null;
58 #endif
59         }
60
61         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "name")]
62         private static string ReadDebugString(string name) {
63 #if DEBUG
64             return ReadString(name);
65 #else
66             return null;
67 #endif
68         }
69
70         private readonly static bool _trackPerformance = ReadDebugOption("TrackPerformance");
71
72         internal static bool TrackPerformance {
73             get { return _trackPerformance; }
74         }
75     }
76 }