Directive.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. using System;
  10. using System.Collections;
  11. namespace System.Web.Compilation
  12. {
  13. sealed class Directive
  14. {
  15. static Hashtable directivesHash;
  16. static string [] page_atts = { "AspCompat", "AutoEventWireup", "Buffer",
  17. "ClassName", "ClientTarget", "CodePage",
  18. "CompilerOptions", "ContentType", "Culture", "Debug",
  19. "Description", "EnableSessionState", "EnableViewState",
  20. "EnableViewStateMac", "ErrorPage", "Explicit",
  21. "Inherits", "Language", "LCID", "ResponseEncoding",
  22. "Src", "SmartNavigation", "Strict", "Trace",
  23. "TraceMode", "Transaction", "UICulture",
  24. "WarningLevel", "CodeBehind" };
  25. static string [] control_atts = { "AutoEventWireup", "ClassName", "CompilerOptions",
  26. "Debug", "Description", "EnableViewState",
  27. "Explicit", "Inherits", "Language", "Strict", "Src",
  28. "WarningLevel", "CodeBehind", "TargetSchema" };
  29. static string [] import_atts = { "namespace" };
  30. static string [] implements_atts = { "interface" };
  31. static string [] assembly_atts = { "name", "src" };
  32. static string [] register_atts = { "tagprefix", "tagname", "Namespace", "Src", "Assembly" };
  33. static string [] outputcache_atts = { "Duration", "Location", "VaryByControl",
  34. "VaryByCustom", "VaryByHeader", "VaryByParam" };
  35. static string [] reference_atts = { "page", "control" };
  36. static string [] webservice_atts = { "class", "codebehind", "debug", "language" };
  37. static string [] application_atts = { "description", "inherits", "codebehind" };
  38. static Directive ()
  39. {
  40. InitHash ();
  41. }
  42. private static void InitHash ()
  43. {
  44. CaseInsensitiveHashCodeProvider provider = new CaseInsensitiveHashCodeProvider ();
  45. CaseInsensitiveComparer comparer = new CaseInsensitiveComparer ();
  46. directivesHash = new Hashtable (provider, comparer);
  47. // Use Hashtable 'cause is O(1) in Contains (ArrayList is O(n))
  48. Hashtable valid_attributes = new Hashtable (provider, comparer);
  49. foreach (string att in page_atts) valid_attributes.Add (att, null);
  50. directivesHash.Add ("PAGE", valid_attributes);
  51. valid_attributes = new Hashtable (provider, comparer);
  52. foreach (string att in control_atts) valid_attributes.Add (att, null);
  53. directivesHash.Add ("CONTROL", valid_attributes);
  54. valid_attributes = new Hashtable (provider, comparer);
  55. foreach (string att in import_atts) valid_attributes.Add (att, null);
  56. directivesHash.Add ("IMPORT", valid_attributes);
  57. valid_attributes = new Hashtable (provider, comparer);
  58. foreach (string att in implements_atts) valid_attributes.Add (att, null);
  59. directivesHash.Add ("IMPLEMENTS", valid_attributes);
  60. valid_attributes = new Hashtable (provider, comparer);
  61. foreach (string att in register_atts) valid_attributes.Add (att, null);
  62. directivesHash.Add ("REGISTER", valid_attributes);
  63. valid_attributes = new Hashtable (provider, comparer);
  64. foreach (string att in assembly_atts) valid_attributes.Add (att, null);
  65. directivesHash.Add ("ASSEMBLY", valid_attributes);
  66. valid_attributes = new Hashtable (provider, comparer);
  67. foreach (string att in outputcache_atts) valid_attributes.Add (att, null);
  68. directivesHash.Add ("OUTPUTCACHE", valid_attributes);
  69. valid_attributes = new Hashtable (provider, comparer);
  70. foreach (string att in reference_atts) valid_attributes.Add (att, null);
  71. directivesHash.Add ("REFERENCE", valid_attributes);
  72. valid_attributes = new Hashtable (provider, comparer);
  73. foreach (string att in webservice_atts) valid_attributes.Add (att, null);
  74. directivesHash.Add ("WEBSERVICE", valid_attributes);
  75. valid_attributes = new Hashtable (provider, comparer);
  76. foreach (string att in application_atts) valid_attributes.Add (att, null);
  77. directivesHash.Add ("APPLICATION", valid_attributes);
  78. }
  79. private Directive () { }
  80. public static bool IsDirective (string id)
  81. {
  82. return directivesHash.Contains (id);
  83. }
  84. }
  85. }