Exemplo n.º 1
0
 public void create <T>(T hostObject = null) where T : class
 {
     RoslynEngine = new ScriptEngine();
     Session      = RoslynEngine.CreateSession(hostObject);
     if (hostObject != null)
     {
         Session.AddReference(hostObject.GetType().Assembly);
     }
     Session.AddReference("System.Web");
     Session.ImportNamespace("System");
     Session.ImportNamespace("System.Web");
 }
        public string test()
        {
            ScriptEngine roslynEngine = new ScriptEngine();

            Roslyn.Scripting.Session session = roslynEngine.CreateSession(this);
            session.AddReference(this.GetType().Assembly);
            session.AddReference("System.Web");
            session.ImportNamespace("System");
            session.ImportNamespace("System.Web");
            var result = (string)session.Execute("Test = Test + \" ... and this was set from roslyn code.\";Test");

            return(result);
        }
        public static T2 evalRet <T, T2>(string strEval, T hostObject = null) where T : class
        {
            ScriptEngine roslynEngine = new ScriptEngine();

            Roslyn.Scripting.Session session = roslynEngine.CreateSession(hostObject);
            if (hostObject != null)
            {
                session.AddReference(hostObject.GetType().Assembly);
            }
            session.AddReference("System.Web");
            session.ImportNamespace("System");
            session.ImportNamespace("System.Web");
            return((T2)session.Execute(strEval));
        }