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 // 9 10 // 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. 29 // 30 using System; 31 using System.Collections.Generic; 32 using System.ComponentModel; 33 using System.Reflection; 34 using System.Web.Configuration; 35 36 namespace System.Web.Util 37 { 38 static class RuntimeHelpers 39 { 40 public static bool CaseInsensitive { 41 get; private set; 42 } 43 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; 49 50 return false; 51 } 52 } 53 54 public static IEqualityComparer <string> StringEqualityComparer { 55 get; private set; 56 } 57 58 public static IEqualityComparer <string> StringEqualityComparerCulture { 59 get; private set; 60 } 61 62 public static bool IsUncShare { 63 get; private set; 64 } 65 66 public static string MonoVersion { 67 get; private set; 68 } 69 70 public static bool RunningOnWindows { 71 get; private set; 72 } 73 74 public static StringComparison StringComparison { 75 get; private set; 76 } 77 78 public static StringComparison StringComparisonCulture { 79 get; private set; 80 } 81 RuntimeHelpers()82 static RuntimeHelpers () 83 { 84 PlatformID pid = Environment.OSVersion.Platform; 85 RunningOnWindows = ((int) pid != 128 && pid != PlatformID.Unix && pid != PlatformID.MacOSX); 86 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 95 } 96 } 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; 108 } 109 } 110 } 111 } 112 } 113 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; 124 } 125 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; 133 } 134 } catch { 135 // ignore 136 } 137 138 if (monoVersion == null) 139 monoVersion = Environment.Version.ToString (); 140 141 MonoVersion = monoVersion; 142 } 143 } 144 } 145