123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #if REFLECTION_EMIT_COMPILER
- using System;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Reflection;
- namespace FastReport.Code.Expressions
- {
- public abstract class ILParser
- {
- private static readonly ConcurrentDictionary<string, MethodInfo> _cache = new ConcurrentDictionary<string, MethodInfo>();
- public static ILParser Create(Report report)
- {
- return new CSharpILParser(report);
- }
- private static object Invoke(MethodInfo method, object[] args)
- {
- var result = method.Invoke(null, args);
- //Debug.WriteLine(result);
- return result;
- }
- public object StartDynamic(string expression, Report report, Variant value)
- {
- if (!_cache.TryGetValue(expression, out var compiledExpression))
- {
- Debug.WriteLine($"Compilation: {expression}");
- compiledExpression = CompileExpression(expression, new[] {report.GetType(), value.GetType()});
- _cache.TryAdd(expression, compiledExpression);
- }
- return Invoke(compiledExpression, new object[] { report, value });
- }
- protected abstract MethodInfo CompileExpression(string expression, Type[] argTypes);
- }
- }
- #endif
|