我知道我可以比较两个PowerShell对象的值:
currentPosition
但是,我需要比较两个PowerShell对象的属性的存在。
这些对象将被视为相同:
let currentPosition = self.selectedRange().location
let currentPositionIndex = command.index(command.startIndex,offsetBy: currentPosition)
if(currentPosition == command.characters.count || command[currentPositionIndex] == " ") {
let separatorsString = " .,:~/!+=\\;/?"
let separators = separatorsString.characters
//TODO: use regex in order to clean the code
var nearestSeparatorPosition = command.startIndex
outerloop: for i in stride(from: currentPosition - 1, to: -1, by: -1) {
for separator in separators {
let index = command.index(command.startIndex, offsetBy: i)
if(command[index] == separator) {
nearestSeparatorPosition = command.index(index, offsetBy: 1)
break outerloop
}
}
}
Swift.print("current word index = (\(command.distance(from: command.startIndex, to: nearestSeparatorPosition)),\(command.distance(from: command.startIndex, to: currentPositionIndex)))")
let currentWord = command.substring(with: nearestSeparatorPosition ..< currentPositionIndex)
这些对象将被视为不相同:
PS> $A = [PsCustomObject]@{"A"=1; "B"=$True; "C"=$False}
PS> $B = [PsCustomObject]@{"A"=1; "B"=$False; "C"=$False}
PS> Compare-Object $A $B -Property A, B, C
A B C SideIndicator
- - - -------------
1 False False =>
1 True False <=
有没有好办法呢?
答案 0 :(得分:1)
我可以想到一些方法来做到这一点,最直接但未经过真正测试:
$A.Keys | ForEach-Object { $C = $B["$_"]; if ($C -eq "") {return $false;} }