update readme (#21797)
[mono-project.git] / mcs / class / System.Web / System.Web.Util / RuntimeHelpers.cs
blob1f06bfb0ad57358367e1328ba81c9f5228676d17
1 //
2 // System.Web.Util.RuntimeHelpers
3 //
4 // Authors:
5 // Marek Habersack (mhabersack@novell.com)
6 //
7 // (C) 2006-2010 Novell, Inc (http://www.novell.com)
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System;
31 using System.Collections.Generic;
32 using System.ComponentModel;
33 using System.Reflection;
34 using System.Web.Configuration;
36 namespace System.Web.Util
38 static class RuntimeHelpers
40 public static bool CaseInsensitive {
41 get; private set;
44 public static bool DebuggingEnabled {
45 get {
46 CompilationSection cs = WebConfigurationManager.GetSection ("system.web/compilation") as CompilationSection;
47 if (cs != null)
48 return cs.Debug;
50 return false;
54 public static IEqualityComparer <string> StringEqualityComparer {
55 get; private set;
58 public static IEqualityComparer <string> StringEqualityComparerCulture {
59 get; private set;
62 public static bool IsUncShare {
63 get; private set;
66 public static string MonoVersion {
67 get; private set;
70 public static bool RunningOnWindows {
71 get; private set;
74 public static StringComparison StringComparison {
75 get; private set;
78 public static StringComparison StringComparisonCulture {
79 get; private set;
82 static RuntimeHelpers ()
84 PlatformID pid = Environment.OSVersion.Platform;
85 RunningOnWindows = ((int) pid != 128 && pid != PlatformID.Unix && pid != PlatformID.MacOSX);
87 if (RunningOnWindows) {
88 CaseInsensitive = true;
89 string appDomainAppPath = AppDomain.CurrentDomain.GetData (".appPath") as string;
90 if (!String.IsNullOrEmpty (appDomainAppPath)) {
91 try {
92 IsUncShare = new Uri (appDomainAppPath).IsUnc;
93 } catch {
94 // ignore
97 } else {
98 string mono_iomap = Environment.GetEnvironmentVariable ("MONO_IOMAP");
99 if (!String.IsNullOrEmpty (mono_iomap)) {
100 if (mono_iomap == "all")
101 CaseInsensitive = true;
102 else {
103 string[] parts = mono_iomap.Split (':');
104 foreach (string p in parts) {
105 if (p == "all" || p == "case") {
106 CaseInsensitive = true;
107 break;
114 if (CaseInsensitive) {
115 StringEqualityComparer = StringComparer.OrdinalIgnoreCase;
116 StringEqualityComparerCulture = StringComparer.CurrentCultureIgnoreCase;
117 StringComparison = StringComparison.OrdinalIgnoreCase;
118 StringComparisonCulture = StringComparison.CurrentCultureIgnoreCase;
119 } else {
120 StringEqualityComparer = StringComparer.Ordinal;
121 StringEqualityComparerCulture = StringComparer.CurrentCulture;
122 StringComparison = StringComparison.Ordinal;
123 StringComparisonCulture = StringComparison.CurrentCulture;
126 string monoVersion = null;
127 try {
128 Type monoRuntime = Type.GetType ("Mono.Runtime", false);
129 if (monoRuntime != null) {
130 MethodInfo mi = monoRuntime.GetMethod ("GetDisplayName", BindingFlags.Static | BindingFlags.NonPublic);
131 if (mi != null)
132 monoVersion = mi.Invoke (null, new object [0]) as string;
134 } catch {
135 // ignore
138 if (monoVersion == null)
139 monoVersion = Environment.Version.ToString ();
141 MonoVersion = monoVersion;