12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System.Reflection;
- using System.Security;
- namespace FastReport.Code
- {
- internal class ExpressionDescriptor
- {
- private string methodName;
- private MethodInfo methodInfo;
- private AssemblyDescriptor assembly;
- public string MethodName
- {
- get { return methodName; }
- set { methodName = value; }
- }
- public object Invoke(object[] parameters)
- {
- if (assembly == null || assembly.Instance == null)
- return null;
- if (methodInfo == null)
- {
- methodInfo = assembly.Instance.GetType().GetMethod(MethodName,
- BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
- }
- if (methodInfo == null)
- return null;
- #if NETCOREAPP
- return methodInfo.Invoke(assembly.Instance, parameters);
- #else
- #pragma warning disable 618
- PermissionSet restrictions = assembly.Report.ScriptRestrictions;
- if (restrictions != null)
- restrictions.Deny();
- try
- {
- return methodInfo.Invoke(assembly.Instance, parameters);
- }
- finally
- {
- if (restrictions != null)
- CodeAccessPermission.RevertDeny();
- }
- #pragma warning restore 618
- #endif
- }
- public ExpressionDescriptor(AssemblyDescriptor assembly)
- {
- this.assembly = assembly;
- }
- }
- }
|