传递和调用System.Action<&燃气轮机;从powershell到c#

传递和调用System.Action<&燃气轮机;从powershell到c#,c#,.net,wpf,powershell,speech-recognition,C#,.net,Wpf,Powershell,Speech Recognition,我正在编写一个c#程序,使用System.Speech.Recognition来识别语音并根据所说的内容运行PowerShell命令 我有以下powershell脚本,它表示用于创建语音命令的宏: Add-Type -Path ".\GAVPI.Lib.dll" Add-Type -Path ".\GAVPI.Lib.Logging.dll" [Action[GAVPI.Lib.Logging.Parameter]]$speechRecognized = { param($i)

我正在编写一个c#程序,使用
System.Speech.Recognition
来识别语音并根据所说的内容运行PowerShell命令

我有以下powershell脚本,它表示用于创建语音命令的宏:

Add-Type -Path ".\GAVPI.Lib.dll"
Add-Type -Path ".\GAVPI.Lib.Logging.dll"

[Action[GAVPI.Lib.Logging.Parameter]]$speechRecognized = {
    param($i) 
    [System.Windows.MessageBox]::Show("test")
}

$parameter = New-Object -TypeName GAVPI.Lib.Logging.Parameter -ArgumentList 
("parameter", "value")

$phrase = New-Object -TypeName GAVPI.Lib.Core.Triggers.Phrase -ArgumentList 
("default","test", $speechRecognized, $parameter)

return $phrase
这个短语object用来告诉我们可以说什么命令,可以识别什么命令。它成功地传递给c#,如下所示:

 var list = new List<Phrase>();

        var ps = PowerShell.Create();
        var run = RunspaceFactory.CreateRunspace();
        ps.Runspace = run;
        run.Open();

        var script = ps.AddScript(".\\PowershellTemplate.ps1", true);
        var result = ps.Invoke();

        foreach (var psObject in result)
        {
            if (psObject.BaseObject is Phrase)
            {
                list.Add((Phrase)psObject.BaseObject);
            }
        }
        return list;

如何将运行空间传递给
Sysem.Action
,以便它可以运行PowerShell脚本块?

有人有什么想法吗?有什么我需要更清楚的吗?也许有更好的办法。基本上,我想让在PowerShell中编写脚本变得容易,从而允许语音命令调用它们。您是否尝试搜索该消息?因为您应该会遇到“是”,我已经查看了这些源代码,但问题是我想调用从PowerShell接收的短语类中的操作。但是,因为它来自Powershell,所以我在尝试调用它时出错。
public override void Run(Parameter selectedparameter)
{

    if (parAction != null)
    {
        parAction.Invoke(selectedparameter);
    }
}
private Action<Parameter> parAction;
param($i)...w("test")