Directive.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. //
  2. // System.Web.Compilation.Directive
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2003 Ximian, Inc (http://www.ximian.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;
  31. using System.Globalization;
  32. namespace System.Web.Compilation
  33. {
  34. sealed class Directive
  35. {
  36. static Hashtable directivesHash;
  37. static string [] page_atts = { "AspCompat", "AutoEventWireup", "Buffer",
  38. "ClassName", "ClientTarget", "CodePage",
  39. "CompilerOptions", "ContentType", "Culture", "Debug",
  40. "Description",
  41. #if NET_2_0
  42. "EnableEventValidation",
  43. #endif
  44. "EnableSessionState", "EnableViewState",
  45. "EnableViewStateMac", "ErrorPage", "Explicit",
  46. "Inherits", "Language", "LCID", "ResponseEncoding",
  47. "Src", "SmartNavigation", "Strict", "Trace",
  48. "TraceMode", "Transaction", "UICulture",
  49. "WarningLevel", "CodeBehind" , "ValidateRequest" };
  50. static string [] control_atts = { "AutoEventWireup", "ClassName", "CompilerOptions",
  51. "Debug", "Description", "EnableViewState",
  52. "Explicit", "Inherits", "Language", "Strict", "Src",
  53. "WarningLevel", "CodeBehind", "TargetSchema" };
  54. static string [] import_atts = { "namespace" };
  55. static string [] implements_atts = { "interface" };
  56. static string [] assembly_atts = { "name", "src" };
  57. static string [] register_atts = { "tagprefix", "tagname", "Namespace", "Src", "Assembly" };
  58. static string [] outputcache_atts = { "Duration", "Location", "VaryByControl",
  59. "VaryByCustom", "VaryByHeader", "VaryByParam" };
  60. static string [] reference_atts = { "page", "control" };
  61. static string [] webservice_atts = { "class", "codebehind", "debug", "language" };
  62. static string [] application_atts = { "description", "inherits", "codebehind" };
  63. #if NET_2_0
  64. static string [] mastertype_atts = { "virtualpath", "typename" };
  65. #endif
  66. static Directive ()
  67. {
  68. InitHash ();
  69. }
  70. private static void InitHash ()
  71. {
  72. #if NET_2_0
  73. StringComparer comparer = StringComparer.InvariantCultureIgnoreCase;
  74. directivesHash = new Hashtable (comparer);
  75. #else
  76. CaseInsensitiveHashCodeProvider provider = new CaseInsensitiveHashCodeProvider (CultureInfo.InvariantCulture);
  77. CaseInsensitiveComparer comparer = new CaseInsensitiveComparer (CultureInfo.InvariantCulture);
  78. directivesHash = new Hashtable (provider, comparer);
  79. #endif
  80. // Use Hashtable 'cause is O(1) in Contains (ArrayList is O(n))
  81. #if NET_2_0
  82. Hashtable valid_attributes = new Hashtable (comparer);
  83. #else
  84. Hashtable valid_attributes = new Hashtable (provider, comparer);
  85. #endif
  86. foreach (string att in page_atts) valid_attributes.Add (att, null);
  87. directivesHash.Add ("PAGE", valid_attributes);
  88. #if NET_2_0
  89. valid_attributes = new Hashtable (comparer);
  90. #else
  91. valid_attributes = new Hashtable (provider, comparer);
  92. #endif
  93. foreach (string att in control_atts) valid_attributes.Add (att, null);
  94. directivesHash.Add ("CONTROL", valid_attributes);
  95. #if NET_2_0
  96. valid_attributes = new Hashtable (comparer);
  97. #else
  98. valid_attributes = new Hashtable (provider, comparer);
  99. #endif
  100. foreach (string att in import_atts) valid_attributes.Add (att, null);
  101. directivesHash.Add ("IMPORT", valid_attributes);
  102. #if NET_2_0
  103. valid_attributes = new Hashtable (comparer);
  104. #else
  105. valid_attributes = new Hashtable (provider, comparer);
  106. #endif
  107. foreach (string att in implements_atts) valid_attributes.Add (att, null);
  108. directivesHash.Add ("IMPLEMENTS", valid_attributes);
  109. #if NET_2_0
  110. valid_attributes = new Hashtable (comparer);
  111. #else
  112. valid_attributes = new Hashtable (provider, comparer);
  113. #endif
  114. foreach (string att in register_atts) valid_attributes.Add (att, null);
  115. directivesHash.Add ("REGISTER", valid_attributes);
  116. #if NET_2_0
  117. valid_attributes = new Hashtable (comparer);
  118. #else
  119. valid_attributes = new Hashtable (provider, comparer);
  120. #endif
  121. foreach (string att in assembly_atts) valid_attributes.Add (att, null);
  122. directivesHash.Add ("ASSEMBLY", valid_attributes);
  123. #if NET_2_0
  124. valid_attributes = new Hashtable (comparer);
  125. #else
  126. valid_attributes = new Hashtable (provider, comparer);
  127. #endif
  128. foreach (string att in outputcache_atts) valid_attributes.Add (att, null);
  129. directivesHash.Add ("OUTPUTCACHE", valid_attributes);
  130. #if NET_2_0
  131. valid_attributes = new Hashtable (comparer);
  132. #else
  133. valid_attributes = new Hashtable (provider, comparer);
  134. #endif
  135. foreach (string att in reference_atts) valid_attributes.Add (att, null);
  136. directivesHash.Add ("REFERENCE", valid_attributes);
  137. #if NET_2_0
  138. valid_attributes = new Hashtable (comparer);
  139. #else
  140. valid_attributes = new Hashtable (provider, comparer);
  141. #endif
  142. foreach (string att in webservice_atts) valid_attributes.Add (att, null);
  143. directivesHash.Add ("WEBSERVICE", valid_attributes);
  144. #if NET_2_0
  145. valid_attributes = new Hashtable (comparer);
  146. #else
  147. valid_attributes = new Hashtable (provider, comparer);
  148. #endif
  149. // same attributes as webservice
  150. foreach (string att in webservice_atts) valid_attributes.Add (att, null);
  151. directivesHash.Add ("WEBHANDLER", valid_attributes);
  152. #if NET_2_0
  153. valid_attributes = new Hashtable (comparer);
  154. #else
  155. valid_attributes = new Hashtable (provider, comparer);
  156. #endif
  157. foreach (string att in application_atts) valid_attributes.Add (att, null);
  158. directivesHash.Add ("APPLICATION", valid_attributes);
  159. #if NET_2_0
  160. valid_attributes = new Hashtable (comparer);
  161. foreach (string att in mastertype_atts) valid_attributes.Add (att, null);
  162. directivesHash.Add ("MASTERTYPE", valid_attributes);
  163. valid_attributes = new Hashtable (comparer);
  164. foreach (string att in control_atts) valid_attributes.Add (att, null);
  165. directivesHash.Add ("MASTER", valid_attributes);
  166. #endif
  167. }
  168. private Directive () { }
  169. public static bool IsDirective (string id)
  170. {
  171. return directivesHash.Contains (id);
  172. }
  173. }
  174. }