Esempio n. 1
0
        /// <summary>
        /// The initialize method of script host class.
        /// </summary>
        private void Initialize()
        {
            // Create the script engine
            // Script engine constructor parameters go changed
            this.engine = new Roslyn.Scripting.CSharp.ScriptEngine();

            // Let us use engine's Addreference for adding the required
            // assemblies
            new[]
            {
                typeof(Console).Assembly, typeof(ScriptingHost).Assembly, typeof(IEnumerable <>).Assembly,
                typeof(IQueryable).Assembly, this.GetType().Assembly
            }.ToList()
            .ForEach(asm => this.engine.AddReference(asm));
            new[] { "System", "System.Linq", "System.Collections", "System.Collections.Generic" }.ToList()
            .ForEach(
                ns =>
                this.engine
                .ImportNamespace(ns));

            /*
             * Now, you need to create a session using engine's CreateSession method,
             * which can be seeded with a host object
             */
            if (this.report != null)
            {
                this.session = this.engine.CreateSession(this.report);
            }
            else
            {
                this.session = this.engine.CreateSession(this);
            }
        }
 public bool RunRule(string content)
 {
     var engine = new Roslyn.Scripting.CSharp.ScriptEngine();
     engine.AddReference(typeof(Console).Assembly);
     var session = engine.CreateSession();
     session.Execute("public bool Run() {" + content + "}");
     return session.Execute<bool>("Run()");
 }
        public bool RunRule(string content)
        {
            var engine = new Roslyn.Scripting.CSharp.ScriptEngine();

            engine.AddReference(typeof(Console).Assembly);
            var session = engine.CreateSession();

            session.Execute("public bool Run() {" + content + "}");
            return(session.Execute <bool>("Run()"));
        }