Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Powershell中的IO FileStream和StreamReader返回null,而在c中则可以_C#_Powershell_System.io.file - Fatal编程技术网

C# Powershell中的IO FileStream和StreamReader返回null,而在c中则可以

C# Powershell中的IO FileStream和StreamReader返回null,而在c中则可以,c#,powershell,system.io.file,C#,Powershell,System.io.file,我用C#创建了一个脚本,出于个人原因,我想在PowerShell中转换它 经过多次尝试,我仍然不明白为什么它仍然给我这个错误,代码有什么问题吗 “无法调用空表达式中的方法。”|当我调用$reader.ReadLine()时 该脚本的目标是读取一个.log文件,并找到有用的信息将其发送到MongoDB数据库 C# 您将System.IO.StreamReader误解为$IOFile。您必须首先在$reader中声明它,如下所示: $reader = New-Object -TypeName Sys

我用C#创建了一个脚本,出于个人原因,我想在PowerShell中转换它

经过多次尝试,我仍然不明白为什么它仍然给我这个错误,代码有什么问题吗

无法调用空表达式中的方法。”|当我调用$reader.ReadLine()时

该脚本的目标是读取一个.log文件,并找到有用的信息将其发送到MongoDB数据库

C#


您将System.IO.StreamReader误解为$IOFile。您必须首先在$reader中声明它,如下所示:

$reader = New-Object -TypeName System.IO.StreamReader -ArgumentList $filePath
[System.IO.File]
在powershell.NET中,类型的调用方式如下:

$reader = New-Object -TypeName System.IO.StreamReader -ArgumentList $filePath
[System.IO.File]

它们的静态方法是通过在“]”后面放置两个冒号来调用的。

我忘了编写它,但我在前面将它设置为一个变量,$IOFile=[System.IO.File]当您将
C
直接转换为
PowerShell
时,这看起来像是pidgin PowerShell。。。为了改进PowerShell语法,我建议您在复杂的。通常,您的脚本流应该是这样的:
Get Content$infle | ForEach Object{…}| Set Content$OutFile