public static TResult ExecuteScriptExpression <TResult> (string expressionScriptSourceCode, params object[] scriptParameter) { const ScriptLanguageType scriptLanguageType = ScriptLanguageType.Python; var engine = ScriptingHost.GetScriptEngine(scriptLanguageType); var scriptSource = engine.CreateScriptSourceFromString(expressionScriptSourceCode, SourceCodeKind.Expression); var compiledScript = scriptSource.Compile(); var scriptScope = ScriptingHost.GetScriptEngine(scriptLanguageType).CreateScope(); for (int i = 0; i < scriptParameter.Length; i++) { scriptScope.SetVariable("p" + i, scriptParameter[i]); } return(compiledScript.Execute <TResult> (scriptScope)); }
public void ImportFromAssemblyIntoScriptScope(ScriptScope scriptScope, string assembly, string nameSpace, string symbol) { string scriptText = @" import clr clr.AddReferenceByPartialName('" + assembly + "')" + @" from " + nameSpace + " import " + symbol; const ScriptLanguageType scriptLanguageType = ScriptLanguageType.Python; var engine = ScriptingHost.GetScriptEngine(scriptLanguageType); var scriptSource = engine.CreateScriptSourceFromString(scriptText, SourceCodeKind.Statements); scriptSource.Execute(scriptScope); }
public object GetAttributeProxy(Object proxied, string attributeName) { var key = new Tuple <Type, string> (proxied.GetType(), attributeName); AttributeProxyCached attributeProxyCached; if (!_proxiedTypeToAttributeProxyCache.TryGetValue(key, out attributeProxyCached)) { object proxy = GetProxy(proxied); var attributeProxy = ScriptingHost.GetScriptEngine(ScriptLanguageType.Python).Operations.GetMember(proxy, attributeName); attributeProxyCached = new AttributeProxyCached(proxy, attributeProxy); _proxiedTypeToAttributeProxyCache[key] = attributeProxyCached; } ((IProxy)attributeProxyCached.Proxy).SetProxied(proxied); return(attributeProxyCached.AttributeProxy); }
public void GetEngine_Static_Fails() { ScriptingHost.GetScriptEngine(ScriptLanguageType.None); }
public void GetEngine_Static() { var pythonEngine = ScriptingHost.GetScriptEngine(ScriptLanguageType.Python); Assert.That(pythonEngine, Is.Not.Null); }