我需要使用 PowerShell 来使用 Google 协议缓冲区。尚未找到特定于语言的转换器,并且使用 protobuf-net (C#) 来生成 .cs 代码和后来的 .dll 文件。
所有找到的方法都涉及 New-Object 构造,但在 protobuf-net.dll 中定义了公共静态类 Serializer,因此无法创建对象(类实例)-> New-Object : Constructor not found。找不到类型 ProtoBuf.Serializer 的合适构造函数。
$memory_stream = New-Object System.IO.MemoryStream
#######
$obj = new-object ControlInterface.EnableGate
$obj.GateId = 2
$obj.Day = 7
#######
$method = [ProtoBuf.Serializer]
$Serialize = $method.GetMethods() | Where-Object {
$_.Name -eq "Serialize" -and
$_.MetadataToken -eq "110665038"
}
$massive = @($memory_stream,$obj)
$closedMethod = $Serialize.MakeGenericMethod([ControlInterface.EnableGate])
$closedMethod.Invoke($method,$massive)
当前错误如下:使用“2”参数调用“Invoke”的异常:“'System.Management.Automation.PSObject' 类型的对象无法转换为'System.IO.Stream' 类型。”
是否可以避免使用 C# 额外代码并仅使用 PowerShell 方法来解决该问题?