CodeCompilerResults.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.CodeDom.Compiler;
  3. using System.Collections.Specialized;
  4. using System.Reflection;
  5. namespace IntelligentControlForsx.CodeGenerator
  6. {
  7. public class CodeCompilerResults
  8. {
  9. private CompilerResults compilerResults;
  10. public CodeCompilerResults(CompilerResults results)
  11. {
  12. compilerResults = results;
  13. }
  14. public bool HasErrors
  15. {
  16. get
  17. {
  18. if (compilerResults == null ||
  19. compilerResults.Errors == null)
  20. return false;
  21. return compilerResults.Errors.HasErrors;
  22. }
  23. }
  24. public bool HasWarnings
  25. {
  26. get
  27. {
  28. if (compilerResults == null ||
  29. compilerResults.Errors == null)
  30. return false;
  31. return compilerResults.Errors.HasWarnings;
  32. }
  33. }
  34. public string ErrorText
  35. {
  36. get
  37. {
  38. if (this.HasErrors)
  39. {
  40. string msg = string.Empty;
  41. foreach (CompilerError ce in compilerResults.Errors)
  42. {
  43. if (ce.IsWarning)
  44. continue;
  45. msg += ce.ErrorText;
  46. }
  47. return msg;
  48. }
  49. return null;
  50. }
  51. }
  52. public string WarningText
  53. {
  54. get
  55. {
  56. if (this.HasWarnings)
  57. {
  58. string msg = string.Empty;
  59. foreach (CompilerError ce in compilerResults.Errors)
  60. {
  61. if (ce.IsWarning)
  62. msg += ce.ErrorText;
  63. }
  64. return msg;
  65. }
  66. return null;
  67. }
  68. }
  69. public Assembly ResultAssembly
  70. {
  71. get
  72. {
  73. if (compilerResults != null)
  74. return compilerResults.CompiledAssembly;
  75. return null;
  76. }
  77. }
  78. public StringCollection Output
  79. {
  80. get
  81. {
  82. if (compilerResults != null)
  83. return compilerResults.Output;
  84. return null;
  85. }
  86. }
  87. public TableModel CreateTableModel(string deviceId)
  88. {
  89. if (this.ResultAssembly != null)
  90. {
  91. Type fType = ResultAssembly.GetTypes()[0];
  92. return (TableModel)ResultAssembly.CreateInstance(fType.FullName, false, BindingFlags.Default, null, new object[] { deviceId }, null, null);
  93. }
  94. return null;
  95. }
  96. }
  97. }