C# 如何使用PowerShell cmdlet中的Get内容?

C# 如何使用PowerShell cmdlet中的Get内容?,c#,visual-studio-2010,powershell,C#,Visual Studio 2010,Powershell,问题在于Visual Studio 2010中使用.Net Framework 4.0中的C的PowerShell 3.0 cmdlet 我们正在编写需要管道输入的PowerShell cmdlet。像 Get-Content .\somefile.bin -Encoding Byte | Receive-Bytes Receive Bytes cmdlet的工作方式与Set Content的工作方式相同。像 Get-Content .\somefile.bin -Encoding Byte

问题在于Visual Studio 2010中使用.Net Framework 4.0中的C的PowerShell 3.0 cmdlet

我们正在编写需要管道输入的PowerShell cmdlet。像

Get-Content .\somefile.bin -Encoding Byte | Receive-Bytes
Receive Bytes cmdlet的工作方式与Set Content的工作方式相同。像

Get-Content .\somefile.bin -Encoding Byte | Set-Content otherfile.bin -Encoding Byte
我们尝试了以下三种选择:

[System.Management.Automation.Parameter(Position = 1, Mandatory = true, ValueFromPipeline = true)]
public byte Input { private get; set; }
public byte[] Input { private get; set; }
public System.IO.BinaryReader Input { private get; set; }
但是。。。字节、字节[]、二进制读取器都会导致相同的错误

+ Get-Content .\somefile.bin | Receive-Bytes
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: [Receive-Bytes], ParameterBindingException
+ FullyQualifiedErrorId : 

Receive-Bytes : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
我们注意到错误重复了好几次,这表明Get内容实际上发送了多个数据块。研究发现情况确实如此,但这并没有让我们离解决问题更近一步

所以。。。问题是:如何设置System.Management.Automation.Parameter以接受从Get Content发送的字节流

更新:下面的答案指向在获取内容时使用-编码字节,在接收字节内使用

public IConvertible Input { private get; set; }
IConvertible获取其中的数据。但是我们在接收字节中获得的内容与我们选择的源文件get Content不匹配

所以。。。如何设置参数以将IConvertible更改回字节流?

是否尝试获取内容。\somefile.bin-编码字节?