using System; using System.CodeDom.Compiler; using System.Collections.Specialized; using System.Reflection; namespace IntelligentControlForsx.CodeGenerator { public class CodeCompilerResults { private CompilerResults compilerResults; public CodeCompilerResults(CompilerResults results) { compilerResults = results; } public bool HasErrors { get { if (compilerResults == null || compilerResults.Errors == null) return false; return compilerResults.Errors.HasErrors; } } public bool HasWarnings { get { if (compilerResults == null || compilerResults.Errors == null) return false; return compilerResults.Errors.HasWarnings; } } public string ErrorText { get { if (this.HasErrors) { string msg = string.Empty; foreach (CompilerError ce in compilerResults.Errors) { if (ce.IsWarning) continue; msg += ce.ErrorText; } return msg; } return null; } } public string WarningText { get { if (this.HasWarnings) { string msg = string.Empty; foreach (CompilerError ce in compilerResults.Errors) { if (ce.IsWarning) msg += ce.ErrorText; } return msg; } return null; } } public Assembly ResultAssembly { get { if (compilerResults != null) return compilerResults.CompiledAssembly; return null; } } public StringCollection Output { get { if (compilerResults != null) return compilerResults.Output; return null; } } public TableModel CreateTableModel(string deviceId) { if (this.ResultAssembly != null) { Type fType = ResultAssembly.GetTypes()[0]; return (TableModel)ResultAssembly.CreateInstance(fType.FullName, false, BindingFlags.Default, null, new object[] { deviceId }, null, null); } return null; } } }