Directive.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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", "MaintainScrollPositionOnPostBack",
  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", "LinePragmas" };
  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. static string [] previouspagetype_atts = { "virtualpath", "typename" };
  66. #endif
  67. static Directive ()
  68. {
  69. InitHash ();
  70. }
  71. private static void InitHash ()
  72. {
  73. #if NET_2_0
  74. StringComparer comparer = StringComparer.InvariantCultureIgnoreCase;
  75. directivesHash = new Hashtable (comparer);
  76. #else
  77. CaseInsensitiveHashCodeProvider provider = new CaseInsensitiveHashCodeProvider (CultureInfo.InvariantCulture);
  78. CaseInsensitiveComparer comparer = new CaseInsensitiveComparer (CultureInfo.InvariantCulture);
  79. directivesHash = new Hashtable (provider, comparer);
  80. #endif
  81. // Use Hashtable 'cause is O(1) in Contains (ArrayList is O(n))
  82. #if NET_2_0
  83. Hashtable valid_attributes = new Hashtable (comparer);
  84. #else
  85. Hashtable valid_attributes = new Hashtable (provider, comparer);
  86. #endif
  87. foreach (string att in page_atts) valid_attributes.Add (att, null);
  88. directivesHash.Add ("PAGE", valid_attributes);
  89. #if NET_2_0
  90. valid_attributes = new Hashtable (comparer);
  91. #else
  92. valid_attributes = new Hashtable (provider, comparer);
  93. #endif
  94. foreach (string att in control_atts) valid_attributes.Add (att, null);
  95. directivesHash.Add ("CONTROL", valid_attributes);
  96. #if NET_2_0
  97. valid_attributes = new Hashtable (comparer);
  98. #else
  99. valid_attributes = new Hashtable (provider, comparer);
  100. #endif
  101. foreach (string att in import_atts) valid_attributes.Add (att, null);
  102. directivesHash.Add ("IMPORT", valid_attributes);
  103. #if NET_2_0
  104. valid_attributes = new Hashtable (comparer);
  105. #else
  106. valid_attributes = new Hashtable (provider, comparer);
  107. #endif
  108. foreach (string att in implements_atts) valid_attributes.Add (att, null);
  109. directivesHash.Add ("IMPLEMENTS", valid_attributes);
  110. #if NET_2_0
  111. valid_attributes = new Hashtable (comparer);
  112. #else
  113. valid_attributes = new Hashtable (provider, comparer);
  114. #endif
  115. foreach (string att in register_atts) valid_attributes.Add (att, null);
  116. directivesHash.Add ("REGISTER", valid_attributes);
  117. #if NET_2_0
  118. valid_attributes = new Hashtable (comparer);
  119. #else
  120. valid_attributes = new Hashtable (provider, comparer);
  121. #endif
  122. foreach (string att in assembly_atts) valid_attributes.Add (att, null);
  123. directivesHash.Add ("ASSEMBLY", valid_attributes);
  124. #if NET_2_0
  125. valid_attributes = new Hashtable (comparer);
  126. #else
  127. valid_attributes = new Hashtable (provider, comparer);
  128. #endif
  129. foreach (string att in outputcache_atts) valid_attributes.Add (att, null);
  130. directivesHash.Add ("OUTPUTCACHE", valid_attributes);
  131. #if NET_2_0
  132. valid_attributes = new Hashtable (comparer);
  133. #else
  134. valid_attributes = new Hashtable (provider, comparer);
  135. #endif
  136. foreach (string att in reference_atts) valid_attributes.Add (att, null);
  137. directivesHash.Add ("REFERENCE", valid_attributes);
  138. #if NET_2_0
  139. valid_attributes = new Hashtable (comparer);
  140. #else
  141. valid_attributes = new Hashtable (provider, comparer);
  142. #endif
  143. foreach (string att in webservice_atts) valid_attributes.Add (att, null);
  144. directivesHash.Add ("WEBSERVICE", valid_attributes);
  145. #if NET_2_0
  146. valid_attributes = new Hashtable (comparer);
  147. #else
  148. valid_attributes = new Hashtable (provider, comparer);
  149. #endif
  150. // same attributes as webservice
  151. foreach (string att in webservice_atts) valid_attributes.Add (att, null);
  152. directivesHash.Add ("WEBHANDLER", valid_attributes);
  153. #if NET_2_0
  154. valid_attributes = new Hashtable (comparer);
  155. #else
  156. valid_attributes = new Hashtable (provider, comparer);
  157. #endif
  158. foreach (string att in application_atts) valid_attributes.Add (att, null);
  159. directivesHash.Add ("APPLICATION", valid_attributes);
  160. #if NET_2_0
  161. valid_attributes = new Hashtable (comparer);
  162. foreach (string att in mastertype_atts) valid_attributes.Add (att, null);
  163. directivesHash.Add ("MASTERTYPE", valid_attributes);
  164. valid_attributes = new Hashtable (comparer);
  165. foreach (string att in control_atts) valid_attributes.Add (att, null);
  166. directivesHash.Add ("MASTER", valid_attributes);
  167. valid_attributes = new Hashtable (comparer);
  168. foreach (string att in previouspagetype_atts) valid_attributes.Add (att, null);
  169. directivesHash.Add ("PREVIOUSPAGETYPE", valid_attributes);
  170. #endif
  171. }
  172. private Directive () { }
  173. public static bool IsDirective (string id)
  174. {
  175. return directivesHash.Contains (id);
  176. }
  177. }
  178. }