PowerShell 4.0
在我的应用程序中,Application
该类具有一组重要的属性、方法和事件。我想通过app
PowerShell 变量与这些成员一起工作(它就像类的别名)。但是Runspace.SessionStateProxy.SetVariable
期望第二个参数中的类实例:
using app = CompanyName.AppName.Application;
...
using (Runspace rs = RunspaceFactory.CreateRunspace()) {
rs.ThreadOptions = PSThreadOptions.UseCurrentThread;
rs.Open();
// TODO: The problem is here (app is not the instance of
//the Application class
rs.SessionStateProxy.SetVariable("app", app);
rs.SessionStateProxy.SetVariable("docs", app.DocumentManager);
using (PowerShell ps = PowerShell.Create()) {
ps.Runspace = rs;
ps.AddScript("$docs.Count");
ps.Invoke();
}
rs.Close();
}
我该怎么做?