我正在使用CS-Script库中的AsmHelper类。我想知道如何只使用一个AsmHelper对象,并且只使用CSScript.LoadCode更改文件路径,这样我就可以在前一个脚本完成后加载一个新脚本,但只有一个AsmHelper对象。现在,如下所示,我有四个AsmHelper对象。
AsmHelper transform1 = new AsmHelper
(CSScript.LoadCode(@"CS-Scripts\parent.cs", null, true));
ITransform engine1 = (ITransform)transform1.CreateObject("Script");
AsmHelper transform2 = new AsmHelper
(CSScript.LoadCode(@"CS-Scripts\bYear.cs", null, true));
ITransform engine2 = (ITransform)transform2.CreateObject("Script");
AsmHelper transform3 = new AsmHelper
(CSScript.LoadCode(@"CS-Scripts\fInitial.cs", null, true));
ITransform engine3 = (ITransform)transform3.CreateObject("Script");
AsmHelper transform4 = new AsmHelper
(CSScript.LoadCode(@"CS-Scripts\pet.cs", null, true));
ITransform engine4 = (ITransform)transform4.CreateObject("Script");如果需要,下面是与之配套的接口:
public interface ITransform
{
User Transform(User record);
}如果你需要我提供更多的细节,请在下面提问。
发布于 2017-07-06 09:30:11
您不应该重用AsmHelper。它早期是为单一脚本用例而设计的。这就是为什么它是IDisposable。
AsmHelper的响应性是通过“Dispatch”调用模型访问脚本方法,处理脚本特定的程序集探测,并在加载到远程AppDomain中时卸载脚本程序集。
由于您没有使用这些特性中的任何一个,因此使用较新的API会更好:
var engine1 = (ITransform)CSScript.LoadCode(@"CS-Scripts\parent.cs", null, true)
.CreateObject("Script");
var engine2 = (ITransform)CSScript.LoadCode(@"CS-Scripts\bYear.cs", null, true)
.CreateObject("Script");
var engine3 = (ITransform)CSScript.LoadCode(@"CS-Scripts\fInitial.cs", null, true)
.CreateObject("Script");
var engine4 = (ITransform)CSScript.LoadCode(@"CS-Scripts\pet.cs", null, true)
.CreateObject("Script");如果您安装了CS-Script NuGet包,它将向您的VS项目添加一些演示这些技术的示例文件。
https://stackoverflow.com/questions/44936951
复制相似问题