CompilerSettings.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. #if NETSTANDARD || NETCOREAPP
  3. using FastReport.Code.CodeDom.Compiler;
  4. using FastReport.Code.CSharp;
  5. #else
  6. using System.CodeDom.Compiler;
  7. using Microsoft.CSharp;
  8. #endif
  9. using System.Collections.Generic;
  10. using System.IO;
  11. using System.Reflection;
  12. using System.Text;
  13. using System.Globalization;
  14. namespace FastReport.Utils
  15. {
  16. /// <summary>
  17. /// Specifies the behaviour of compiler when exception is thrown.
  18. /// </summary>
  19. public enum CompilerExceptionBehaviour
  20. {
  21. /// <summary>
  22. /// Default behaviour. Throw exception.
  23. /// </summary>
  24. Default,
  25. /// <summary>
  26. /// Show exception message and replace incorrect expression by <b>Placeholder</b>.
  27. /// </summary>
  28. ShowExceptionMessage,
  29. /// <summary>
  30. /// Replace expression with exception message. Don't show any messages.
  31. /// </summary>
  32. ReplaceExpressionWithExceptionMessage,
  33. /// <summary>
  34. /// Replace exception with <b>Placeholder</b> value. Don't show any messages.
  35. /// </summary>
  36. ReplaceExpressionWithPlaceholder
  37. }
  38. /// <summary>
  39. /// Contains compiler settings.
  40. /// </summary>
  41. public class CompilerSettings
  42. {
  43. #region Fields
  44. private string placeholder;
  45. private CompilerExceptionBehaviour exceptionBehaviour;
  46. #endregion Fields
  47. #region Properties
  48. /// <summary>
  49. /// Gets or set the string that will be used for replacing incorrect expressions.
  50. /// </summary>
  51. public string Placeholder
  52. {
  53. get { return placeholder; }
  54. set { placeholder = value; }
  55. }
  56. /// <summary>
  57. /// Gets or sets the behaviour of compiler when exception is thrown.
  58. /// </summary>
  59. public CompilerExceptionBehaviour ExceptionBehaviour
  60. {
  61. get { return exceptionBehaviour; }
  62. set { exceptionBehaviour = value; }
  63. }
  64. /// <summary>
  65. /// Get or sets number of recompiles
  66. /// </summary>
  67. /// <remarks>
  68. /// Report compiler can try to fix compilation errors and recompile your report again. This property sets the number of such attempts.
  69. /// </remarks>
  70. public int RecompileCount { get; set; } = 1;
  71. #if REFLECTION_EMIT_COMPILER
  72. /// <summary>
  73. /// Enables faster compiler if the report script hasn't been changed
  74. /// </summary>
  75. public bool ReflectionEmitCompiler { get; set; } = false;
  76. #endif
  77. #if CROSSPLATFORM || COREWIN
  78. // sets by user
  79. private CultureInfo cultureInfo;
  80. /// <summary>
  81. /// Sets culture for compiler
  82. /// </summary>
  83. public CultureInfo CultureInfo
  84. {
  85. get
  86. {
  87. if(cultureInfo == null)
  88. {
  89. return Res.CurrentCulture;
  90. }
  91. return cultureInfo;
  92. }
  93. set
  94. {
  95. cultureInfo = value;
  96. }
  97. }
  98. #endif
  99. #endregion Properties
  100. #region Constructors
  101. /// <summary>
  102. /// Initializes a new instance of the <see cref="CompilerSettings"/> class.
  103. /// </summary>
  104. public CompilerSettings()
  105. {
  106. placeholder = "";
  107. exceptionBehaviour = CompilerExceptionBehaviour.Default;
  108. }
  109. #endregion Constructors
  110. }
  111. }