public Delegate CompileLambdaString(string source) { source = @" class Remote{ public static object GetLambda(){ return new System.Func<object, System.Threading.Tasks.Task<object>>(" + source + @"); } } "; /* * string sha1 = GetSha1Id(source); * if (AssemblyCache.ContainsKey(sha1)) * { * manager.LoadAssemblyInfo(AssemblyCache[sha1]); * return null; * }*/ var compiler = new DynamicRun.Builder.Compiler("compiled.dll", manager.LoadedAssemblies.ToArray()); byte[] data = compiler.Compile(source); Assembly a = Assembly.Load(data); Type t = a.GetType("Remote"); var Func = (Func <object>)Delegate.CreateDelegate(typeof(Func <object>), t.GetMethod("GetLambda")); return((Delegate)Func()); }
public Assembly CompileString(string source) { string sha1 = GetSha1Id(source); if (AssemblyCache.ContainsKey(sha1)) { manager.LoadAssemblyInfo(AssemblyCache[sha1]); return(AssemblyCache[sha1].assembly); } var compiler = new DynamicRun.Builder.Compiler("compiled" + (count++).ToString() + ".dll", manager.LoadedAssemblies.ToArray()); byte[] data = compiler.Compile(source); AssemblyInfo ax = new AssemblyInfo(); ax.assembly = Assembly.Load(data); ax.rawData = data; manager.LoadAssemblyInfo(ax); AssemblyCache[sha1] = ax; return(ax.assembly); }