Cómo crear un objeto comparable a través de -eq
, como un objeto .NET. Por ejemplo:
class test{ $a $b test($a,$b){ $this.a=$a $this.b=$b } } $obj = [test]::new(4, 5) $obj -eq [test]::new(4, 5) # False $pt = [System.Drawing.Point]::new(4, 5) $pt -eq [System.Drawing.Point]::new(4, 5) # True
Según la documentación :
Para crear clases comparables, debe implementar
System.IEquatable<T>
en su clase.
class MyFileInfoSet : System.IEquatable[Object] { [String]$File [Int64]$Size [bool] Equals([Object] $obj) { return ($this.File -eq $obj.File) -and ($this.Size -eq $obj.Size) } } $a = [MyFileInfoSet]@{File = "C:\Windows\explorer.exe"; Size = 4651032} $b = [MyFileInfoSet]@{File = "C:\Windows\explorer.exe"; Size = 4651032} $a -eq $b