PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/Source/WebCodeProviders/CSharpCodeProviderWithDocs.cs

#
C# | 117 lines | 40 code | 9 blank | 68 comment | 0 complexity | 4b0f168403567de12ee633476d4643d7 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. //=============================================================================
  2. // System : EWSoftware Custom Code Providers
  3. // File : CSharpCodeProviderWithDocs.cs
  4. // Author : Eric Woodruff (Eric@EWoodruff.us)
  5. // Updated : 02/03/2009
  6. // Note : Copyright 2008-2009, Eric Woodruff, All rights reserved
  7. // Compiler: Microsoft Visual C#
  8. //
  9. // This file contains a custom C# code provider that is able to output an
  10. // individual XML comments file for each unit that is compiled to a folder
  11. // of your choice. This changes the default behavior which overwrites the
  12. // comments file on each invocation and dumps it into the temporary ASP.NET
  13. // compilation folder.
  14. //
  15. // This code is published under the Code Project Open License (CPOL). A copy
  16. // of the license can be found at: http://www.codeproject.com/info/cpol10.aspx.
  17. // This notice, the author's name, and all copyright notices must remain intact
  18. // in all applications, documentation, and source files.
  19. //
  20. // Version Date Who Comments
  21. // ============================================================================
  22. // 1.0.0.0 04/06/2008 EFW Created the code
  23. // 1.1.0.0 02/03/2009 EFW Added support for providerOptions
  24. //=============================================================================
  25. using System;
  26. using System.CodeDom;
  27. using System.CodeDom.Compiler;
  28. using System.Collections.Generic;
  29. using Microsoft.CSharp;
  30. namespace EWSoftware.CodeDom
  31. {
  32. /// <summary>
  33. /// This is a custom C# code provider that is able to output an individual
  34. /// XML comments file for each unit that is compiled to a folder of your
  35. /// choice.
  36. /// </summary>
  37. /// <remarks>This changes the default behavior which overwrites the
  38. /// comments file on each invocation and dumps it into the temporary
  39. /// ASP.NET compilation folder.
  40. ///
  41. /// <p/>A <c>/docpath:[path]</c> option should be added to the
  42. /// <c>compilerOptions</c> attribute in the <b>Web.config</b> file to
  43. /// specify the path to which the XML comments files will be written.
  44. /// The filenames will match the assembly names generated by the
  45. /// compiler.</remarks>
  46. /// <example>
  47. /// <code lang="xml" title="Example Compiler Configuration">
  48. /// <![CDATA[
  49. /// <configuration>
  50. /// <system.codedom>
  51. /// <compilers>
  52. /// <!-- For C# -->
  53. /// <compiler language="c#;cs;csharp" extension=".cs"
  54. /// compilerOptions="/docpath:C:\Publish\Doc"
  55. /// type="EWSoftware.CodeDom.CSharpCodeProviderWithDocs,
  56. /// EWSoftware.CodeDom, Version=1.0.0.0, Culture=neutral,
  57. /// PublicKeyToken=d633d7d5b41cbb65" />
  58. /// </compilers>
  59. /// </system.codedom>
  60. /// </configuration>]]>
  61. /// </code>
  62. /// </example>
  63. public class CSharpCodeProviderWithDocs : CSharpCodeProvider
  64. {
  65. #region Constructors
  66. //=====================================================================
  67. /// <summary>
  68. /// Default constructor
  69. /// </summary>
  70. /// <overloads>There are two overloads for the constructor</overloads>
  71. public CSharpCodeProviderWithDocs() : base()
  72. {
  73. }
  74. /// <summary>
  75. /// This constructor is passed a provider options dictionary
  76. /// </summary>
  77. /// <param name="providerOptions">The provider options</param>
  78. public CSharpCodeProviderWithDocs(
  79. IDictionary<string, string> providerOptions) : base(providerOptions)
  80. {
  81. }
  82. #endregion
  83. #region CodeDomProvider overrides
  84. //=====================================================================
  85. /// <inheritdoc />
  86. public override CompilerResults CompileAssemblyFromDom(
  87. CompilerParameters options, params CodeCompileUnit[] compilationUnits)
  88. {
  89. CodeProviderHelper.ReplaceDocPathOption(options, null);
  90. return base.CompileAssemblyFromDom(options, compilationUnits);
  91. }
  92. /// <inheritdoc />
  93. public override CompilerResults CompileAssemblyFromFile(
  94. CompilerParameters options, params string[] fileNames)
  95. {
  96. CodeProviderHelper.ReplaceDocPathOption(options, null);
  97. return base.CompileAssemblyFromFile(options, fileNames);
  98. }
  99. /// <inheritdoc />
  100. public override CompilerResults CompileAssemblyFromSource(
  101. CompilerParameters options, params string[] sources)
  102. {
  103. CodeProviderHelper.ReplaceDocPathOption(options, null);
  104. return base.CompileAssemblyFromSource(options, sources);
  105. }
  106. #endregion
  107. }
  108. }