CodeHelper.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Reflection;
  6. #if NETSTANDARD || NETCOREAPP
  7. using FastReport.Code.CodeDom.Compiler;
  8. #else
  9. using System.CodeDom.Compiler;
  10. #endif
  11. using FastReport.Data;
  12. using FastReport.Engine;
  13. using FastReport.Utils;
  14. namespace FastReport.Code
  15. {
  16. internal abstract partial class CodeHelperBase
  17. {
  18. #region Fields
  19. private Report report;
  20. #endregion
  21. #region Properties
  22. public Report Report
  23. {
  24. get { return report; }
  25. }
  26. #endregion
  27. #region Protected Methods
  28. protected string StripEventHandlers(Hashtable events)
  29. {
  30. using (Report report = new Report())
  31. {
  32. report.LoadFromString(Report.SaveToString());
  33. report.ScriptText = EmptyScript();
  34. List<Base> list = new List<Base>();
  35. foreach (Base c in report.AllObjects)
  36. {
  37. list.Add(c);
  38. }
  39. list.Add(report);
  40. foreach (Base c in list)
  41. {
  42. PropertyInfo[] props = c.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
  43. foreach (PropertyInfo info in props)
  44. {
  45. if (info.PropertyType == typeof(string) && info.Name.EndsWith("Event"))
  46. {
  47. string value = (string)info.GetValue(c, null);
  48. if (!String.IsNullOrEmpty(value))
  49. {
  50. string cName = c.Name + ".";
  51. if (c is Report)
  52. cName = "";
  53. events.Add(cName + info.Name.Replace("Event", ""), value);
  54. info.SetValue(c, "", null);
  55. }
  56. }
  57. }
  58. }
  59. return report.SaveToString();
  60. }
  61. }
  62. protected abstract string GetTypeDeclaration(Type type);
  63. #endregion
  64. #region Public Methods
  65. public abstract string EmptyScript();
  66. public abstract CodeDomProvider GetCodeProvider();
  67. public abstract int GetPositionToInsertOwnItems(string scriptText);
  68. public abstract string AddField(Type type, string name);
  69. public abstract string BeginCalcExpression();
  70. public abstract string AddExpression(string expr, string value);
  71. public abstract string EndCalcExpression();
  72. public abstract string ReplaceColumnName(string name, Type type);
  73. public abstract string ReplaceParameterName(Parameter parameter);
  74. public abstract string ReplaceVariableName(Parameter parameter);
  75. public abstract string ReplaceTotalName(string name);
  76. public abstract string GenerateInitializeMethod();
  77. public abstract string ReplaceClassName(string scriptText, string className);
  78. public abstract string GetMethodSignature(MethodInfo info, bool fullForm);
  79. public abstract string GetMethodSignatureAndBody(MethodInfo info);
  80. public abstract string GetPropertySignature(PropertyInfo info, bool fullForm);
  81. #endregion
  82. public CodeHelperBase(Report report)
  83. {
  84. this.report = report;
  85. }
  86. }
  87. }