/// <summary>Compile the code or expression and return a delegate of type Func to execute.</summary> /// <param name="code">The code or expression to compile.</param> /// <param name="type1">The first type used to compile the code or expression.</param> /// <returns>A delegate of type Func that represents the compiled code or expression.</returns> public Task <Func <object, object> > CompileAsync(string code, Type type1) { return(EvalCompiler.CompileAsync <Func <object, object> >(this, code, new Dictionary <string, Type> { { "{0}", type1 } }, typeof(object), EvalCompilerParameterKind.Untyped)); }
/// <summary>Compile the code or expression and return a TDelegate of type Func or Action to execute.</summary> /// <typeparam name="TDelegate">Type of the delegate (Func or Action) to use to compile the code or expression.</typeparam> /// <param name="code">The code or expression to compile.</param> /// <param name="parameterNames">Parameter names used to compile the code or expressions.</param> /// <returns>A TDelegate of type Func or Action that represents the compiled code or expression.</returns> public Task <TDelegate> CompileAsync <TDelegate>(string code, params string[] parameterNames) { var parameterTypes = new Dictionary <string, Type>(); var tDelegate = typeof(TDelegate); var arguments = tDelegate.GetGenericArguments(); var isAction = tDelegate.FullName.StartsWith("System.Action"); var tReturn = isAction ? null : arguments.Last(); var lastArgumentPosition = isAction ? arguments.Length : arguments.Length - 1; for (var i = 0; i < lastArgumentPosition; i++) { if (parameterNames != null && i <= parameterNames.Length) { parameterTypes.Add(parameterNames[i], arguments[i]); } else { parameterTypes.Add(string.Concat("{", i, "}"), arguments[i]); } } return(EvalCompiler.CompileAsync <TDelegate>(this, code, parameterTypes, tReturn, EvalCompilerParameterKind.Typed)); }
/// <summary>Compile the code or expression and return a delegate of type Func to execute.</summary> /// <param name="code">The code or expression to compile.</param> /// <param name="parameterTypes">Parameter types used to compile the code or expression.</param> /// <returns>A delegate of type Func that represents the compiled code or expression.</returns> public Task <Func <IEnumerable, object> > CompileAsync(string code, params Type[] parameterTypes) { var dict = new Dictionary <string, Type>(); for (var i = 0; i < parameterTypes.Length; i++) { dict.Add(string.Concat("{", i, "}"), parameterTypes[i]); } return(EvalCompiler.CompileAsync <Func <IEnumerable, object> >(this, code, dict, typeof(object), EvalCompilerParameterKind.Enumerable)); }
/// <summary>Compile the code or expression and return a delegate of type Func to execute.</summary> /// <param name="code">The code or expression to compile.</param> /// <param name="type1">The first type used to compile the code or expression.</param> /// <param name="type2">The second type used to compile the code or expression.</param> /// <param name="type3">The third type used to compile the code or expression.</param> /// <param name="type4">The fourth type used to compile the code or expression.</param> /// <param name="type5">The fifth type used to compile the code or expression.</param> /// <returns>A delegate of type Func that represents the compiled code or expression.</returns> public Task <Func <object, object, object, object, object, object> > CompileAsync(string code, Type type1, Type type2, Type type3, Type type4, Type type5) { return(EvalCompiler.CompileAsync <Func <object, object, object, object, object, object> >(this, code, new Dictionary <string, Type> { { "{0}", type1 }, { "{1}", type2 }, { "{2}", type3 }, { "{3}", type4 }, { "{4}", type5 } }, typeof(object), EvalCompilerParameterKind.Untyped)); }
/// <summary>Compile and evaluate the code or expression and return the result of type TResult.</summary> /// <typeparam name="TResult">Type of the result of the evaluted code or expression.</typeparam> /// <param name="code">The code or expression to evaluate.</param> /// <returns>The evaluated result of type TResult or null that represents the evaluted code or expression.</returns> public async Task <TResult> ExecuteAsync <TResult>(string code) { return(EvalCompiler.CompileAsync <Func <TResult> >(this, code, null, typeof(TResult), EvalCompilerParameterKind.None).Result()); }
/// <summary>Compile the code or expression and return a delegate of type Func to execute.</summary> /// <param name="code">The code or expression to compile.</param> /// <param name="parameterTypes">Parameter types used to compile the code or expression.</param> /// <returns>A delegate of type Func that represents the compiled code or expression.</returns> public Task <Func <IDictionary, object> > CompileAsync(string code, IDictionary <string, Type> parameterTypes) { return(EvalCompiler.CompileAsync <Func <IDictionary, object> >(this, code, parameterTypes, typeof(object), EvalCompilerParameterKind.Dictionary)); }
/// <summary>Compile the code or expression and return a delegate of type Func to execute.</summary> /// <param name="code">The code or expression to compile.</param> /// <returns>A delegate of type Func that represents the compiled code or expression.</returns> public Task <Func <object> > CompileAsync(string code) { return(EvalCompiler.CompileAsync <Func <object> >(this, code, null, typeof(object), EvalCompilerParameterKind.None)); }