Compiler.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // System.Web.Configuration.CompilerCollection
  3. //
  4. // Authors:
  5. // Chris Toshok ([email protected])
  6. //
  7. // (C) 2005 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. #if NET_2_0
  30. #if CONFIGURATION_2_0
  31. using System;
  32. using System.CodeDom.Compiler;
  33. using System.ComponentModel;
  34. using System.Configuration;
  35. namespace System.Web.Configuration
  36. {
  37. public sealed class Compiler : ConfigurationElement
  38. {
  39. static ConfigurationProperty compilerOptionsProp;
  40. static ConfigurationProperty extensionProp;
  41. static ConfigurationProperty languageProp;
  42. static ConfigurationProperty typeProp;
  43. static ConfigurationProperty warningLevelProp;
  44. static ConfigurationPropertyCollection properties;
  45. static Compiler ()
  46. {
  47. compilerOptionsProp = new ConfigurationProperty("compilerOptions", typeof (string), "");
  48. extensionProp = new ConfigurationProperty("extension", typeof (string), "");
  49. languageProp = new ConfigurationProperty("language", typeof (string), "", ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
  50. typeProp = new ConfigurationProperty("type", typeof (string), "", ConfigurationPropertyOptions.IsRequired);
  51. warningLevelProp = new ConfigurationProperty("warningLevel", typeof (int), 0,
  52. TypeDescriptor.GetConverter (typeof (int)),
  53. new IntegerValidator (0, 4),
  54. ConfigurationPropertyOptions.None);
  55. properties = new ConfigurationPropertyCollection ();
  56. properties.Add (compilerOptionsProp);
  57. properties.Add (extensionProp);
  58. properties.Add (languageProp);
  59. properties.Add (typeProp);
  60. properties.Add (warningLevelProp);
  61. }
  62. internal Compiler ()
  63. {
  64. }
  65. public Compiler (string compilerOptions, string extension, string language, string type, int warningLevel)
  66. {
  67. this.CompilerOptions = compilerOptions;
  68. this.Extension = extension;
  69. this.Language = language;
  70. this.Type = type;
  71. this.WarningLevel = warningLevel;
  72. }
  73. [ConfigurationProperty ("compilerOptions", DefaultValue = "")]
  74. public string CompilerOptions {
  75. get { return (string) base[compilerOptionsProp]; }
  76. internal set { base[compilerOptionsProp] = value; }
  77. }
  78. [ConfigurationProperty ("extension", DefaultValue = "")]
  79. public string Extension {
  80. get { return (string) base[extensionProp]; }
  81. internal set { base[extensionProp] = value; }
  82. }
  83. [ConfigurationProperty ("language", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey)]
  84. public string Language {
  85. get { return (string) base[languageProp]; }
  86. internal set { base[languageProp] = value; }
  87. }
  88. [ConfigurationProperty ("type", DefaultValue = "", Options = ConfigurationPropertyOptions.IsRequired)]
  89. public string Type {
  90. get { return (string) base[typeProp]; }
  91. internal set { base[typeProp] = value; }
  92. }
  93. [IntegerValidator (MinValue = 0, MaxValue = 4)]
  94. [ConfigurationProperty ("warningLevel", DefaultValue = "0")]
  95. public int WarningLevel {
  96. get { return (int) base[warningLevelProp]; }
  97. internal set { base[warningLevelProp] = value; }
  98. }
  99. protected override ConfigurationPropertyCollection Properties {
  100. get { return properties; }
  101. }
  102. #region CompatabilityCode
  103. [MonoTODO ("we shouldn't need this")]
  104. CodeDomProvider provider;
  105. internal CodeDomProvider Provider {
  106. get {
  107. if (provider == null) {
  108. Type t = System.Type.GetType (this.Type);
  109. provider = Activator.CreateInstance (t) as CodeDomProvider;
  110. }
  111. return provider;
  112. }
  113. set {
  114. provider = value;
  115. }
  116. }
  117. #endregion
  118. }
  119. }
  120. #endif
  121. #endif