- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为 powershell 上的演示文稿编写一些简短的演示脚本,当然我自己的一个简单演示让我感到困惑。此演示的目的是展示在 powershell 中创建对象的不同方法。这是我的代码:
$file = ls 'C:\temp' | Where-Object {$_.Extension -eq '.txt'}
$file.FullName
$path = 'C:\temp\jdh.txt'
$newfile = New-Object -TypeName System.IO.FileInfo -ArgumentList $path
$newfile.FullName
$file.GetType()
$newfile.GetType()
$file
$newfile
$file | Get-Content | out-null
$newfile | Get-Content | out-null
C:\temp\jdh.txt
C:\temp\jdh.txt
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True FileInfo System.IO.FileSystemInfo
True True FileInfo System.IO.FileSystemInfo
LastWriteTime : 4/10/2013 3:38:29 PM
Length : 46046
Name : jdh.txt
LastWriteTime : 4/10/2013 3:38:29 PM
Length : 46046
Name : jdh.txt
Get-Content : 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.
At line:16 char:12
+ $newfile | Get-Content | out-null
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (C:\temp\jdh.txt:PSObject) [Get-Content], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.GetContentCommand
最佳答案
我跟踪了使用 New-Object
创建的对象的绑定(bind)。问题是 Get-Content
无法绑定(bind)到 FileInfo
上的任何属性信息对象。
您可以使用以下命令进行检查:
Trace-Command -psHost -Name ParameterBinding {$newFile | gc}
Trace-Command -psHost -Name ParameterBinding {$file | gc}
Microsoft.PowerShell.Core\FileSystem::
开头的属性。这是 PsPath。因此,仔细检查比较管道时的对象属性
Get-Member
你会看到一个有效的具有这些注释属性,而使用
New-Object
创建的那个具有这些注释属性。才不是 -
Get-Content
cmdlet参数我们可以看到
LiteralPath
别名为
PsPath
:
(Get-Command -Name Get-Content).ParameterSets
Parameter Name: LiteralPath
ParameterType = System.String[]
Position = 0
IsMandatory = True
IsDynamic = False
HelpMessage =
ValueFromPipeline = False
ValueFromPipelineByPropertyName = True
ValueFromRemainingArguments = False
Aliases = {PSPath}
Attributes =
System.Management.Automation.AliasAttribute
System.Management.Automation.ParameterAttribute
New-Object
已创建
FileInfo
它会起作用:
$newFile | Add-Member -MemberType NoteProperty -Name PsPath -Value 'Microsoft.PowerShell.Core\FileSystem::C:\temp\jdh.txt'
关于Powershell:所有新对象都不是平等的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16016166/
我一直在努力理解 Javascript 的相等性。你能告诉我为什么以下行返回 false 吗? ? alert((function a(){}) == (function a(){})) // fal
scala 中有一个特别的问题每次都困扰着我。每次它咬我...它咬得很重... 为什么这一行编译通过 val x = "10" if (x != 10) { print("do somethin
我正在努力解决我网站的问题。 我想制作 与具有宽度 960px 的主体相等.我的代码有什么问题或缺失?对不起,我不能直接在这里发布代码,不允许我这样做。这是我的文件的链接: https://githu
我希望这些实例的原型(prototype)相同,但以下相等性检查的计算结果为 false。 var emp1 = new(EmployeeScope())("John"); var emp2 = ne
Hamcrest 中是否有匹配器来比较集合的相等性?有 contains 和 containsInAnyOrder 但我需要 equals 不绑定(bind)到具体的集合类型。例如。我无法将 Arra
struct Something { union { float k; int n; }; bool isFloat; bool ope
是否有 == 的等价物?但结果是x != NA如果 x不是 NA ? 以下是我想要的,但它很笨重: mapply(identical, vec1, vec2) 最佳答案 只需将“==”替换为 %in%
无论如何,我认为这是个问题。我正在使用一个 RelayCommand,它用两个委托(delegate)装饰一个 ICommand。一个是 _canExecute 的 Predicate,另一个是 _e
假设我有一个界面 interface IFoo{ val foo:String } 我想创建等于IFF的foo字符串匹配的类。 简单的例子: class A(override val foo:
谁能解释一下下面这部分代码的含义: private event UserChangedHandler m_UserChanged; public event UserChangedHandler Us
(为冗长的设置道歉。这里有一个问题,我保证。) 考虑一个类 Node具有在构建时分配的不可变唯一 ID。此 ID 用于在持久化对象图时进行序列化等。例如,当一个对象被反序列化时,它会根据 ID 针对主
Ruby API说: The eql? method returns true if obj and other refer to the same hash key. 我更改了 Object 的哈希
在我的 Nant 脚本中,我想将属性值与已知字符串进行比较。看完Nant Expressions文档 我相信我可以做一个基本的“==”比较来评估为 bool 值。 但是鉴于脚本块: 执行时,
简化示例: 我最近设置了 Single Table Inheritance在 Animal 上模型。 Cat和 Dog是 Animal 的子类. 我有一个 Animal工厂 : factory :an
如何使用 NHibernate 通过以下测试? 我认为只需覆盖实体类中的 Equals 和 GetHashCode 就足以使其按照我希望的方式工作。显然,对于非常微不足道的“点”对象,为相同的坐标保留
我是一名优秀的程序员,十分优秀!