public HostedScriptEngine StartEngine() { engine = new HostedScriptEngine(); engine.Initialize(); engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(OMyGodEco))); // Подключаем тестовую оболочку engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(EngineHelpWrapper))); var testrunnerSource = LoadFromAssemblyResource("NUnitTests.Tests.testrunner.os"); var testrunnerModule = engine.GetCompilerService() .Compile(testrunnerSource); { var mi = engine.GetType().GetMethod("SetGlobalEnvironment", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance); mi.Invoke(engine, new object[] { this, testrunnerSource }); } engine.LoadUserScript(new ScriptEngine.UserAddedScript() { Type = ScriptEngine.UserAddedScriptType.Class, Image = testrunnerModule, Symbol = "TestRunner" }); var testRunner = AttachedScriptsFactory.ScriptFactory("TestRunner", new IValue[] { }); TestRunner = ValueFactory.Create(testRunner); return(engine); }
public HostedScriptEngine StartEngine() { engine = new HostedScriptEngine(); engine.Initialize(); // Тут можно указать любой класс из компоненты engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(oscriptcomponent.MyClass))); // Если проектов компонент несколько, то надо взять по классу из каждой из них // engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(oscriptcomponent_2.MyClass_2))); // engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(oscriptcomponent_3.MyClass_3))); // Подключаем тестовую оболочку engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(EngineHelpWrapper))); var testrunnerSource = LoadFromAssemblyResource("NUnitTests.Tests.testrunner.os"); var testrunnerModule = engine.GetCompilerService().Compile(testrunnerSource); { var mi = engine.GetType().GetMethod("SetGlobalEnvironment", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance); mi.Invoke(engine, new object[] { this, testrunnerSource }); } engine.LoadUserScript(new ScriptEngine.UserAddedScript() { Type = ScriptEngine.UserAddedScriptType.Class, Image = testrunnerModule, Symbol = "TestRunner" }); var testRunner = AttachedScriptsFactory.ScriptFactory("TestRunner", new IValue[] { }); TestRunner = ValueFactory.Create(testRunner); return(engine); }