RuntimeHelpers.cs 4.1 KB

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