I am trying to write a comparer for my own class.
As I want everything to work in both Windows PowerShell (5.1) up till PowerShell 7, I am writing everything for Windows PowerShell first and then test PowerShell 7. Now suddenly my whole module doesn’t load any more using module .MyModule
or using the Install-Module .MyModule
and returns any error:
Import-Module: Specified method is not supported.
After, removing everything that isn’t related to the error, I have nailed the problem down to:
class MyClass {}
class MyComparer : Collections.Generic.IComparer[MyClass] {
[String]$PrimaryKey # Should always become first
[int] Compare ([MyClass]$Value1, [MyClass]$Value2) { return 0 }
}
Note that this (as my whole module) works fine in Windows PowerShell 5.1 and also if:
- if I remove the line:
[String]$PrimaryKey # Should always become first
- or if I change the item type from
[MyClass
]to e.g.
[Object]`, like:
class MyComparer : Collections.Generic.IComparer[Object] {
[String]$PrimaryKey # Should always be first
[int] Compare ([Object]$Value1, [Object]$Value2) { return 0 }
}
This is really at the edge of what I understand of (comparer) interfaces and I wonder if I am actually doing something wrong here or whether this concerns a (PowerShell 7) bug…