PowerShell classes still can't create value types
See original GitHub issueSteps to reproduce
Try to implement any interfaces that is intended to be implemented in terms of yourself, E.g. IEquatable, IComparable:
class ServerName : Object, System.IEquatable[ServerName] {
[string]$ComputerName
[bool] Equals([ServerName]$other) {
return $this.ComputerName.Equals($other.ComputerName);
}
}
Expected behavior
I should be able to write IEquatable<T> and IComparable<T> classes
Actual behavior
A runtime compile error:
An error occurred while creating the pipeline.
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : RuntimeException
Environment data
Any version of PowerShell since classes were introduced, up to and including 7 Pre 4
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Powershell custom class creation question
I think the issue stems from having objects of type [node] in the current powershell session, then redefining the [node] type.
Read more >about Classes - PowerShell
Describes how you can use classes to create your own custom types.
Read more >PowerShell 5: Create Simple Class - Scripting Blog
Summary: Ed Wilson, Microsoft Scripting Guy, talks about creating a simple class in Windows PowerShell 5.0 in Windows 10.
Read more >PowerShell Classes: Getting Started
In this tutorial, you're going to learn how to get started with PowerShell classes. You'll create your first class with constructors, learn how ......
Read more >Using Static Classes and Methods - PowerShell
This article explains how to identify and use the properties and methods of .NET static classes.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@SeeminglyScience thanks. Believe it or not it totally worked 😃 Full code:
Outputted the textual representation in green to the host.
@JustinGrote Method names are case sensitive for declaration:
Though be aware that it’s likely that
OnNext
will be called on a thread without a default runspace. If that’s the case, the method will just throw.