using FastReport.Code; using FastReport.Data; using FastReport.Utils; using System; using System.Collections.Generic; using System.Diagnostics; namespace FastReport { public partial class Report { #if REFLECTION_EMIT_COMPILER private readonly Dictionary _cachedParsedExpressions = new Dictionary(); private Code.Expressions.ILParser _ilParser; private bool IsCompileNeeded { get; set; } #endif #region Script related #if REFLECTION_EMIT_COMPILER private void SetIsCompileNeeded() { // we check report object to AdvMatrix, because this object doesn't work without compilation if (!scriptChanged) { foreach (var reportObject in AllObjects) { if (reportObject is ReportComponentBase reportObj) if (reportObj.IsCompilationNeeded) { IsCompileNeeded = true; break; } } } else IsCompileNeeded = scriptChanged; if (!IsCompileNeeded) _ilParser = Code.Expressions.ILParser.Create(this); } private bool TryReflectionEmit(string expression, Variant value, out object returnValue) { returnValue = null; if (IsCompileNeeded) return false; try { if (!_cachedParsedExpressions.TryGetValue(expression, out var result)) { result = expression; // TODO: optimize if (DataHelper.IsValidColumn(Report.Dictionary, expression)) result = "[" + expression + "]"; result = AssemblyDescriptor.ReplaceDataItems(this, result); _cachedParsedExpressions.Add(expression, result); } returnValue = _ilParser.StartDynamic(result, this, value); return true; } catch (Exception ex) { Debug.WriteLine($"ERROR in compilation expression {expression}, message: {ex.Message}"); Config.WriteLogString(ex.Message); return false; } } #endif #endregion Script related } }